#include "operatorimporter.h"
#include <QFont>
#include <QFontMetrics>


OperatorImporter::OperatorImporter(QObject *parent) : QObject(parent)
{

}

void OperatorImporter::dataProcess_64(OperatorData &datas,QDomDocument &doc)
{    

    //变量处理
    QHash<QString,QString> hash;
    hash["int8"]="int";
    hash["int16"]="short";
    hash["int32"]="int";
    hash["int64"]="int";
    hash["float32"]="float";
    hash["float64"]="float";
    hash["uint8"]="uint";
    hash["uint16"]="ushort";
    hash["uint32"]="uint";
    hash["uint64"]="uint";

    for(int i=0;i<datas.variables.size();i++)
    {
        if(hash.contains(datas.variables.at(i).dataType))
        {
            datas.variables[i].dataType=hash.value(datas.variables.at(i).dataType);
        }


        QDomNode varNode=datas.variables.at(i).node;

        QDomNodeList nodeList=varNode.childNodes();

        QDomNode typeNode;

        QDomNode defaultNode;

        QDomNode lastNode;

        QDomNode pragmasNode;


        for(int i=0;i<nodeList.size();i++)
        {
            if(nodeList.at(i).toElement().tagName()=="type")
                typeNode=varNode.childNodes().at(i);

            if(nodeList.at(i).toElement().tagName()=="default")
                defaultNode=varNode.childNodes().at(i);

            if(nodeList.at(i).toElement().tagName()=="last")
                lastNode=varNode.childNodes().at(i);

            if(nodeList.at(i).toElement().tagName()=="pragmas")
                pragmasNode=varNode.childNodes().at(i);
        }


        QDomNode idNode=pragmasNode.firstChild();

        QDomNode commentNode=idNode.firstChild();

        QString oid;//oid
        QString comment;//注释

        oid=QUuid::createUuid().toString(QUuid::WithoutBraces);

        if(!commentNode.isNull())
            comment=commentNode.toElement().text();

        if(!defaultNode.isNull())
            varNode.removeChild(defaultNode);

        if(!lastNode.isNull())
            varNode.removeChild(lastNode);

        varNode.removeChild(pragmasNode);

        QDomElement oidEle=doc.createElement("oid");
        oidEle.setAttribute("value",oid);
        varNode.appendChild(oidEle);

        if(!comment.isEmpty())
        {
            QDomElement pragmasEle=doc.createElement("pragmas");
            varNode.appendChild(pragmasEle);

            QDomElement commentEle=doc.createElement("comment");
            commentEle.setAttribute("value",comment);
            pragmasEle.appendChild(commentEle);
        }


        QDomNode indexNode=typeNode.firstChild();

        //处理变量的数据类型引用了包中的数据类型
        if(indexNode.toElement().tagName()=="NamedType")
        {
            QDomNode typeRefNode=indexNode.firstChild().firstChild();

            if(typeRefNode.toElement().tagName()=="TypeRef")
            {
                QString name=typeRefNode.toElement().attribute("name");

                if(typeRefNode.toElement().attribute("name").contains("::"))
                {
                    QStringList list=name.split("::");
                    name=list.at(list.size()-1);
                    typeRefNode.toElement().setAttribute("name",name);
                }


                if(hash.contains(name))
                {
                    typeRefNode.toElement().setAttribute("name",hash.value(name));
                }


            }
        }

        //处理结构体变量的结构体元素的oid
        if(indexNode.toElement().tagName()=="Struct")
        {
            QDomNode fieldsNode=indexNode.firstChild();

            QDomNodeList nodeList=fieldsNode.childNodes();

            for(int i=0;i<nodeList.size();i++)
            {
                QDomNode node=nodeList.at(i);

                QDomNodeList fieldChild=node.childNodes();

                for(int i=0;i<fieldChild.size();i++)
                {
                    QDomNode childNode=fieldChild.at(i);

                    if(childNode.toElement().tagName()=="type")
                    {
                        QDomNode fieldType=childNode.firstChild();
                        if(fieldType.toElement().tagName()=="NamedType")
                        {
                            QString type=fieldType.firstChild().firstChild().toElement().attribute("name");
                            if(hash.contains(type))
                            {
                                fieldType.firstChild().firstChild().toElement().setAttribute("name",hash.value(type));
                            }
                        }

                        //结构体嵌套结构体
                        if(fieldType.toElement().tagName()=="Struct")
                        {
                            QDomNode fieldsNode=fieldType.firstChild();
                            QDomNodeList nodeList=fieldsNode.childNodes();

                            for(int i=0;i<nodeList.size();i++)
                            {
                                QDomNode node=nodeList.at(i);
                                QDomNodeList fieldChild=node.childNodes();

                                for(int i=0;i<fieldChild.size();i++)
                                {
                                    QDomNode childNode=fieldChild.at(i);

                                    if(childNode.toElement().tagName()=="pragmas")
                                    {
                                        QDomNode fieldOid=childNode;

                                        fieldOid.toElement().setTagName("oid");

                                        fieldOid.toElement().setAttribute("value",QUuid::createUuid().toString(QUuid::WithoutBraces));

                                        fieldOid.removeChild(fieldOid.firstChild());
                                    }
                                }

                            }
                        }
                    }

                    if(childNode.toElement().tagName()=="pragmas")
                    {
                        QDomNode fieldOid=childNode;

                        fieldOid.toElement().setTagName("oid");

                        fieldOid.toElement().setAttribute("value",QUuid::createUuid().toString(QUuid::WithoutBraces));

                        fieldOid.removeChild(fieldOid.firstChild());
                    }
                }
            }
        }

        //处理结构体数组中结构体元素的oid
        if(indexNode.toElement().tagName()=="Table")
        {
            QDomNode index=indexNode.firstChild().firstChild();

            if(index.toElement().tagName()=="NamedType")
            {
                QString type=index.firstChild().firstChild().toElement().attribute("name");
                if(hash.contains(type))
                {
                    index.firstChild().firstChild().toElement().setAttribute("name",hash.value(type));
                }
            }

            if(index.toElement().tagName()=="Struct")
            {
                QDomNode fieldsNode=index.firstChild();

                QDomNodeList nodeList=fieldsNode.childNodes();

                for(int i=0;i<nodeList.size();i++)
                {
                    QDomNode node=nodeList.at(i);

                    QDomNodeList fieldChild=node.childNodes();

                    for(int i=0;i<fieldChild.size();i++)
                    {
                        QDomNode childNode=fieldChild.at(i);

                        if(childNode.toElement().tagName()=="pragmas")
                        {
                            QDomNode fieldOid=childNode;

                            fieldOid.toElement().setTagName("oid");

                            fieldOid.toElement().setAttribute("value",QUuid::createUuid().toString(QUuid::WithoutBraces));

                            fieldOid.removeChild(fieldOid.firstChild());
                        }
                    }
                }
            }
        }

        datas.variables[i].node=varNode;
    }

    //页面处理
    diagramProcess(datas);


    //逻辑
    for(int i=0;i<datas.equations.size();i++)
    {

        Equation equation=datas.equations.at(i);

        QDomNode equationNode=equation.node.cloneNode(true);

        equationNode.toElement().setAttribute("oid",equation.pageId);

        QDomNode leftsNode;

        QDomNode rightNode;

        QDomNode pragmasNode;

        for(int j=0;j<equationNode.childNodes().size();j++)
        {
            if(equationNode.childNodes().at(j).toElement().tagName()=="lefts")
                leftsNode=equationNode.childNodes().at(j);

            if(equationNode.childNodes().at(j).toElement().tagName()=="right")
            {
                rightNode=equationNode.childNodes().at(j);

                if(rightNode.firstChild().toElement().tagName()=="Last")
                {
                    rightNode.firstChild().toElement().setTagName("IdExpression");
                    rightNode.firstChild().firstChild().toElement().setTagName("path");
                }

                //'\x00'改为'/x00'
                if(equation.type=="immediate"&&equation.rightVarRef=="'\\x00'")
                {
                    QDomNode constValueNode=rightNode.firstChild();
                    constValueNode.toElement().setAttribute("value","'/x00'");
                }

                if(equation.operatorType=="OpCall")
                {
                    QDomNode opCallNode=rightNode.childNodes().at(1).firstChild().firstChild();

                    QDomNodeList nodeList=opCallNode.childNodes();

                    for(int i=0;i<nodeList.size();i++)
                    {
                        QDomNode node=nodeList.at(i);

                        if(node.toElement().tagName()=="operator")
                        {
                            QDomNode operatorRefNode=node.firstChild();

                            QString operatorRefName=operatorRefNode.toElement().attribute("name");

                            if(operatorRefName.contains("::"))
                            {
                                QStringList list=operatorRefName.split("::");

                                operatorRefName=list.at(list.size()-1);
                                operatorRefNode.toElement().setAttribute("name",operatorRefName);


                            }

                        }

                        if(node.toElement().tagName()=="pragmas")
                        {
                            opCallNode.removeChild(node);
                        }
                    }
                }

                //修改调用了含参数的操作符的equation
                if(equation.isParaHigh&&m_operator.hasPara==false)
                {

                    QDomNodeList nodeList=rightNode.childNodes();

                    QDomNode callExpressionNode;

                    QDomNode opCallNode;

                    for(int i=0;i<nodeList.size();i++)
                    {
                        if(!nodeList.at(i).isComment())
                        {
                            callExpressionNode=nodeList.at(i);
                        }
                    }

                    opCallNode=callExpressionNode.firstChild().firstChild();

                    nodeList=opCallNode.childNodes();

                    for(int i=0;i<nodeList.size();i++)
                    {

                        if(nodeList.at(i).toElement().tagName()=="operator")
                        {
                            opCallNode.childNodes().at(i).firstChild().toElement().setAttribute("name",opCallNode.childNodes().at(i).firstChild().toElement().attribute("name")+"_"+equation.paraValue.value);
                        }
                    }

                    opCallNode.removeChild(opCallNode.childNodes().at(1));
                    callExpressionNode.firstChild().firstChild()=opCallNode;
                    rightNode.childNodes().at(1)=callExpressionNode;

                }

                equationNode.childNodes().at(j)=rightNode;
            }

            if(equationNode.childNodes().at(j).toElement().tagName()=="pragmas")
                pragmasNode=equationNode.childNodes().at(j);
        }

        QDomNode idNode=pragmasNode.firstChild();

        QDomNode commentNode=idNode.firstChild();

        QString oid;//oid
        QString comment;//注释

        oid=QUuid::createUuid().toString(QUuid::WithoutBraces);

        if(!commentNode.isNull())
            comment=commentNode.toElement().text();

        equationNode.removeChild(pragmasNode);

        QDomElement oidEle=doc.createElement("oid");
        oidEle.setAttribute("value",oid);
        equationNode.appendChild(oidEle);

        if(!comment.isEmpty())
        {
            QDomElement pragmasEle=doc.createElement("pragmas");
            equationNode.appendChild(pragmasEle);

            QDomElement commentEle=doc.createElement("comment");
            commentEle.setAttribute("value",comment);
            pragmasEle.appendChild(commentEle);
        }

        datas.equations[i].node=equationNode;
    }

}

void OperatorImporter::correctionOperatorFile(QFile &file)
{
    //校正属性顺序
    QString strAll;
    QStringList strList;

    if(file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        QTextStream stream(&file);
        stream.setCodec("UTF-8");
        strAll=stream.readAll();
    }

    file.close();

    if(file.open(QIODevice::WriteOnly|QIODevice::Text))
    {
        QTextStream stream(&file);
        stream.setCodec("utf-8");
        strList=strAll.split("\n");

        for(int i=0;i<strList.size();i++)
        {
            //Operator的kind、external、name顺序
            if(strList.at(i).contains("Operator")&&strList.at(i).contains("kind=")&&strList.at(i).contains("name="))
            {
                int kindIndex=strList.at(i).indexOf("kind=");
                int nameIndex=strList.at(i).indexOf("name=");

                QString kindStr=strList.at(i).mid(kindIndex);
                QString nameStr=strList.at(i).mid(nameIndex);

                int kindEndIndex=kindStr.indexOf(" ")-1;
                int nameEndIndex=nameStr.indexOf(" ")-1;

                //导入操作符
                if(strList.at(i).contains("external="))
                {
                    int externalIndex=strList.at(i).indexOf("external=");

                    QString externalStr=strList.at(i).mid(externalIndex);

                    int externalEndIndex=externalStr.indexOf(" ")-1;

                    if(kindIndex>nameIndex&&kindIndex>externalIndex)
                    {
                        kindEndIndex=kindStr.indexOf(">")-1;

                    }

                    if(nameIndex>kindIndex&&nameIndex>externalIndex)
                    {
                        nameEndIndex=nameStr.indexOf(">")-1;
                    }

                    if(externalIndex>kindIndex&&externalIndex>nameIndex)
                    {
                        externalEndIndex=externalStr.indexOf(">")-1;
                    }

                    QString kindString=kindStr.mid(0,kindEndIndex+1);
                    QString externalString=externalStr.mid(0,externalEndIndex+1);
                    QString nameString=nameStr.mid(0,nameEndIndex+1);

                    strList[i]="    <Operator "+kindString+" "+externalString+" "+nameString+">";

                }
                else {
                    if(kindIndex>nameIndex)
                    {
                        kindEndIndex=kindStr.indexOf(">")-1;

                    }

                    if(nameIndex>kindIndex)
                    {
                        nameEndIndex=nameStr.indexOf(">")-1;
                    }

                    QString kindString=kindStr.mid(0,kindEndIndex+1);
                    QString nameString=nameStr.mid(0,nameEndIndex+1);

                    strList[i]="    <Operator "+kindString+" "+nameString+">";
                }

            }

            //组合运算操作符的name和operator顺序
            if(strList.at(i).contains("UnaryOp")||strList.at(i).contains("BinaryOp")||strList.at(i).contains("NAryOp"))
            {
                if(strList.at(i).contains("name=")&&strList.at(i).contains("operator="))
                {
                    int nameIndex=strList.at(i).indexOf("name=");
                    int operatorIndex=strList.at(i).indexOf("operator=");

                    if(nameIndex>operatorIndex)
                    {
                        QString str=strList.at(i).mid(operatorIndex);

                        int operatorEndIndex=str.indexOf(" ")-1;
                        int nameBeginIndex=operatorEndIndex+2;

                        QString operatorString=str.mid(0,operatorEndIndex+1);
                        QString nameString=str.mid(nameBeginIndex,str.length()-operatorString.length()-2);

                        strList[i]=strList.at(i).mid(0,operatorIndex-1)+" "+nameString+" "+operatorString+">";
                    }
                }
            }

            //高阶操作符的name和iterator顺序
            if(strList.at(i).contains("IteratorOp")||strList.at(i).contains("PartialIteratorOp"))
            {
                if(strList.at(i).contains("name=")&&strList.at(i).contains("iterator="))
                {
                    int nameIndex=strList.at(i).indexOf("name=");
                    int iteratorIndex=strList.at(i).indexOf("iterator=");

                    if(nameIndex>iteratorIndex)
                    {
                        QString str=strList.at(i).mid(iteratorIndex);

                        int iteratorEndIndex=str.indexOf(" ")-1;
                        int nameBeginIndex=iteratorEndIndex+2;

                        QString iteratorString=str.mid(0,iteratorEndIndex+1);
                        QString nameString=str.mid(nameBeginIndex,str.length()-iteratorString.length()-2);

                        strList[i]=strList.at(i).mid(0,iteratorIndex-1)+" "+nameString+" "+iteratorString+">";
                    }

                }
            }

            //'\x00'->'/x00'
            if(strList.at(i).contains("'\\x00'"))
            {
                strList[i].replace("'\\x00'","'/x00'");
            }


            stream<<strList.at(i)<<endl;
        }
    }

    file.close();
}

void OperatorImporter::saveOperatorFile_64(const QString &redaceProjectPath,const QString &scadeProjectName,const QString &operatorFileName,OperatorData &datas)
{
    QString filePath=redaceProjectPath+"/"+scadeProjectName+"/"+operatorFileName;
    QFile file(filePath);
    QFileInfo fileInfo=QFileInfo(filePath);

    if(!file.open(QFile::WriteOnly|QFile::Truncate))
        return;

    QXmlStreamWriter writer(&file);

    writer.setAutoFormatting(true);
    writer.setAutoFormattingIndent(2);

    //写入StartDocument
    writer.writeStartDocument();

    //写File节点
    writer.writeStartElement("File");
    writer.writeAttribute("Type","Operator");

    //declarations
    writer.writeStartElement("declarations");

    //Operator
    writer.writeStartElement("Operator");
    writer.writeAttribute("kind",datas.kind);

    if(datas.isImported==true)
        writer.writeAttribute("external","imported");

    writer.writeAttribute("name",datas.operatorName);

    //operator_property
    writer.writeStartElement("operator_property");
    writer.writeAttribute("description",datas.comment);
    writer.writeAttribute("subFolderName","");
    writer.writeAttribute("isInSubFolder","False");

    if(datas.isImported==false)
    {
        writer.writeAttribute("isImportOpe","false");
        writer.writeAttribute("cFilePath","");
        writer.writeAttribute("hFilePath","");
    }
    else
    {
        writer.writeAttribute("isImportOpe","true");
        writer.writeAttribute("cFilePath",redaceProjectPath+"/"+scadeProjectName+"/acg_imported/"+datas.operatorName+".c");
        writer.writeAttribute("hFilePath",redaceProjectPath+"/"+scadeProjectName+"/acg_imported/"+datas.operatorName+".h");
    }


    writer.writeAttribute("stylePath","");
    writer.writeEndElement();//结束operator_property

    //inputs
    bool hasInput=false;
    for(int i=0;i<datas.variables.size();i++)
    {
        if(datas.variables.at(i).type=="input")
        {
            hasInput=true;
        }
    }
    if(hasInput==true)
    {
        writer.writeStartElement("inputs");

        writer.writeEndElement();
    }


    //outputs
    bool hasOutput=false;
    for(int i=0;i<datas.variables.size();i++)
    {
        if(datas.variables.at(i).type=="output")
        {
            hasOutput=true;
        }
    }
    if(hasOutput==true)
    {
        writer.writeStartElement("outputs");

        writer.writeEndElement();
    }

    //locals
    bool hasLocal=false;
    for(int i=0;i<datas.variables.size();i++)
    {
        if(datas.variables.at(i).type=="local")
        {
            hasLocal=true;
        }
    }
    if(hasLocal==true)
    {
        writer.writeStartElement("locals");

        writer.writeEndElement();
    }

    //data
    if(!datas.equations.isEmpty())
    {
        writer.writeStartElement("data");

        writer.writeEndElement();
    }

    //oid
    writer.writeStartElement("oid");
    writer.writeAttribute("value",QUuid::createUuid().toString(QUuid::WithoutBraces));
    writer.writeEndElement();//结束oid

    //diagrams
    if(!datas.diagrams.isEmpty())
    {
        writer.writeStartElement("diagrams");
        for(int i=0;i<datas.diagrams.size();i++)
        {
            writer.writeStartElement("NetDiagram");
            writer.writeAttribute("name",datas.diagrams.at(i).name);
            writer.writeAttribute("landscape",datas.diagrams.at(i).landscape);
            writer.writeAttribute("oid",datas.diagrams.at(i).redaceOid);
            writer.writeAttribute("EleIDIndex","");
            writer.writeAttribute("OutPortIndex","");
            writer.writeAttribute("ProjectName","");
            writer.writeAttribute("DiagramName","");
            writer.writeAttribute("DiagramId","");
            writer.writeAttribute("Description","");
            writer.writeAttribute("DiagramNum","");
            writer.writeAttribute("DiagramVersion","");
            writer.writeAttribute("DesignPersonName","");
            writer.writeAttribute("DesignTime","");
            writer.writeAttribute("CheckPersonName","");
            writer.writeAttribute("CheckTime","");
            writer.writeAttribute("DeterminePersonName","");
            writer.writeAttribute("DetermineTime","");
            writer.writeAttribute("ApprovePersonName","");
            writer.writeAttribute("ApproveTime","");
            writer.writeAttribute("FDDiagram","False");
            writer.writeAttribute("BackgroundImageWidth","0");
            writer.writeAttribute("BackgroundImageHeight","0");
            writer.writeAttribute("BackgroundImageFileName","");

            writer.writeEndElement();
        }
        writer.writeEndElement();
    }


    writer.writeEndElement();//结束data

    writer.writeEndElement();//结束Operator

    writer.writeEndElement();//结束declarations

    writer.writeEndElement();//结束File

    writer.writeEndDocument();

    file.close();

    QDomDocument doc;

    if(!doc.setContent(&file))
    {
        file.close();
        return;
    }

    file.close();

    if(datas.isNew==false)
    {
        dataProcess_64(m_operator,doc);
    }

    QDomElement root = doc.documentElement();
    QDomElement declarations = root.firstChild().toElement();

    QDomNode operatorNode=declarations.firstChild();

    QDomNodeList itemList=operatorNode.childNodes();

    for(int i=0;i<itemList.size();i++)
    {
        //inputs
        if(itemList.at(i).toElement().tagName()=="inputs")
        {
            for(int j=0;j<datas.variables.size();j++)
            {
                if(datas.variables.at(j).type=="input")
                    operatorNode.childNodes().at(i).appendChild(datas.variables.at(j).node);

            }
        }

        //outputs
        if(itemList.at(i).toElement().tagName()=="outputs")
        {
            for(int j=0;j<datas.variables.size();j++)
            {
                if(datas.variables.at(j).type=="output")
                    operatorNode.childNodes().at(i).appendChild(datas.variables.at(j).node);

            }
        }

        //locals
        if(itemList.at(i).toElement().tagName()=="locals")
        {
            for(int j=0;j<datas.variables.size();j++)
            {
                if(datas.variables.at(j).type=="local")
                    operatorNode.childNodes().at(i).appendChild(datas.variables.at(j).node);

            }
        }

        //data
        if(itemList.at(i).toElement().tagName()=="data")
        {
            for(int j=0;j<datas.equations.size();j++)
            {
                operatorNode.childNodes().at(i).appendChild(datas.equations.at(j).node);

            }
        }
    }

    if(file.open(QFile::WriteOnly|QFile::Truncate))
    {
        QTextStream stream( &file );
        stream.setCodec("utf-8");
        doc.save(stream,2,QDomNode::EncodingFromTextStream);
    }

    file.close();

    //校正属性顺序
    correctionOperatorFile(file);
}

bool OperatorImporter::readOperatorFile(const QDomNode &root)
{

    QDomElement element=root.toElement();
    m_operator.kind=element.attribute("kind");

    if(element.hasAttribute("external")&&element.attribute("external")=="imported")//判断是否为导入操作符
    {
        m_operator.isImported=true;
        m_operator.logList.append(m_operator.operatorName+"为导入操作符;");
    }


    QDomNodeList items = element.childNodes();
    for (int i = 0;i < items.count();i++)
    {
        QDomNode item = items.at(i);
        element = item.toElement();

        //获取参数列表(暂时只考虑一个参数的情况)
        if(element.tagName()=="sizeParameters")
        {
            QDomNodeList paraList=element.childNodes();
            for(int i=0;i<paraList.size();i++)
            {
                if(paraList.at(i).toElement().tagName()=="SizeParameter")
                {
                    QString paraName=paraList.at(i).toElement().attribute("name");

                    m_operator.parameter=paraName;
                }
            }

            m_operator.hasPara=true;
            m_operator.logList.append("包含参数；");

        }

        //获取所有变量节点，解析变量数据
        if(element.tagName()=="inputs"||element.tagName()=="outputs"||element.tagName()=="locals")
        {
            parseVariables(element);
        }

        //获取所有逻辑节点，解析逻辑数据
        if(element.tagName()=="data")
        {
            parseDatas(element);
        }

        //解析pragmas节点，获取操作符oid和画面信息
        if(element.tagName()=="pragmas")
        {
            parsePragmas(element);
        }
    }

    return true;
}

void OperatorImporter::dataProcess(QFile &file,OperatorData &datas)
{
    if( !file.open(QIODevice::Append | QIODevice::Text) )
        return;

    QTextStream out(&file);

    //操作符oid修改
    datas.oid=QUuid::createUuid().toString(QUuid::WithoutBraces);

    //变量处理
    QHash<QString,QString> hash;
    hash["int8"]="int";
    hash["int16"]="short";
    hash["int32"]="int";
    hash["int64"]="int";
    hash["float32"]="float";
    hash["float64"]="float";
    hash["uint8"]="uint";
    hash["uint16"]="ushort";
    hash["uint32"]="uint";
    hash["uint64"]="uint";

    //变量数据类型转换，oid修改
    for(int i=0;i<datas.variables.size();i++)
    {
        datas.variables[i].id=QUuid::createUuid().toString(QUuid::WithoutBraces);
        //普通变量
        if(datas.variables.at(i).isArray==false&&datas.variables.at(i).isStruct==false)
        {
            if(hash.contains(datas.variables.at(i).dataType))
            {
                out<<QString("变量")+datas.variables.at(i).name+QString("的数据类型发生转换：")+datas.variables[i].dataType+QString("->")+hash.value(datas.variables.at(i).dataType)<<endl;
                datas.variables[i].dataType=hash.value(datas.variables.at(i).dataType);
            }
        }

        //结构体变量
        if(datas.variables.at(i).isStruct==true)
        {
            for(int j=0;j<datas.variables.at(i).fieldList.size();j++)
            {
                datas.variables[i].fieldList[j].oid=QUuid::createUuid().toString(QUuid::WithoutBraces);
                if(hash.contains(datas.variables.at(i).fieldList.at(j).type))
                {
                    datas.variables[i].fieldList[j].type=hash.value(datas.variables.at(i).fieldList.at(j).type);

                }

            }
        }

        //数组变量
        if(datas.variables.at(i).isArray==true&&hash.contains(datas.variables.at(i).array.type))
        {
            datas.variables[i].array.type=hash.value(datas.variables.at(i).array.type);
        }

    }

    //逻辑处理
    for(int i=0;i<datas.equations.size();i++)
    {
        datas.equations[i].redaceId=QUuid::createUuid().toString(QUuid::WithoutBraces);
    }

    file.close();

    //页面处理
    diagramProcess(datas);
}                       

void OperatorImporter::diagramProcess(OperatorData &datas)
{
    int EleID=0;

    for(int i=0;i<datas.diagrams.size();i++)
    {

        Diagram diagram=datas.diagrams.at(i);

        QList<int> equationDelIndex;//被移除的图元的下标

        //图元。处理x,y,width,height,EleID;解析端口
        for(int j=0;j<diagram.equations.size();j++)
        {
            Equation equation=diagram.equations.at(j);

            //在画面中删除结束符和REDACE不支持的操作符
            if(equation.type=="terminator"||equation.isUnsupport==true)
            {
                equationDelIndex.append(j);
                //                diagram.equations.removeAt(j);
                continue;
            }

            equation.id=EleID;
            datas.diagrams[i].equations[j].id=EleID;

            EleID++;

            //图元坐标值缩小
            equation.x=equation.x/ZOOM;
            equation.y=equation.y/ZOOM;

            //宽高
            //输入变量
            if(equation.type=="inputVar")
            {
                equation.eleType="ELETYPE_IN_VAR";
                equation.text=equation.name;

                QFont font;
                font.setPointSize(10);
                QFontMetrics fontMetrics(font);
                QRectF textRect = fontMetrics.boundingRect(equation.text);
                equation.width=20+textRect.width();
                equation.height=30;

                equation.x=equation.x-equation.width;

                int gap=equation.height/2;
                portCoordinate outport;
                outport.type="out";
                outport.x=equation.x+equation.width;
                outport.y=equation.y+gap-5;
                equation.outList.append(outport);

            }

            //输出变量、本地变量
            if(equation.type=="outputVar"||equation.type=="localInputVar"||equation.type=="localOutputVar")
            {
//                equation.width=70;
                equation.height=30;
                equation.text=equation.name;

                QFont font;
                font.setPointSize(10);
                QFontMetrics fontMetrics(font);
                QRectF textRect = fontMetrics.boundingRect(equation.text);

                equation.width=20+textRect.width();


                if(equation.type=="outputVar")
                {
                    equation.eleType="ELETYPE_OUT_VAR";

                    int gap=equation.height/2;
                    portCoordinate inport;
                    inport.type="in";
                    inport.x=equation.x;
                    inport.y=equation.y+gap-5;
                    equation.inList.append(inport);

                    equation.rightList.append(equation.inList);
                }

                if(equation.type=="localInputVar")
                {
                    equation.eleType="ELETYPE_LOCAL_IN_VAR";

                    equation.x=equation.x-equation.width;

                    int gap=equation.height/2;
                    portCoordinate outport;
                    outport.type="out";
                    outport.x=equation.x+equation.width;
                    outport.y=equation.y+gap-5;
                    equation.outList.append(outport);
                }

                if(equation.type=="localOutputVar")
                {
                    equation.eleType="ELETYPE_LOCAL_OUT_VAR";

                    int gap=equation.height/2;
                    portCoordinate inport;
                    inport.type="in";
                    inport.x=equation.x;
                    inport.y=equation.y+gap-5;
                    equation.inList.append(inport);

                    equation.rightList.append(equation.inList);
                }
            }

            //立即数
            if(equation.type=="immediate")
            {
                QFont font;
                font.setPointSize(10);
                QFontMetrics fontMetrics(font);
                QRectF textRect = fontMetrics.boundingRect(equation.text);

                equation.width=32+textRect.width();
                //equation.width=32+4*equation.text.length();
                equation.height=30;

                equation.x=equation.x-equation.width;

                equation.eleType="ELETYPE_IMMEDIATE";
                //                equation.text=equation.rightVarRef;

                int gap=equation.height/2;
                portCoordinate outport;
                outport.type="out";
                outport.x=equation.x+equation.width;
                outport.y=equation.y+gap-5;
                equation.outList.append(outport);

            }

            //常量
            if(equation.type=="constant")
            {
//                equation.width=72;
                equation.height=30;

                equation.eleType="ELETYPE_CONST";
                equation.text=equation.name;

                QFont font;
                font.setPointSize(10);
                QFontMetrics fontMetrics(font);
                QRectF textRect = fontMetrics.boundingRect(equation.text);

                equation.width=20+textRect.width();
                //equation.width=32+6*equation.text.length();

                equation.x=equation.x-equation.width;

                int gap=equation.height/2;
                portCoordinate outport;
                outport.type="out";
                outport.x=equation.x+equation.width;
                outport.y=equation.y+gap-5;
                equation.outList.append(outport);
            }

            //非高阶操作符
            if(equation.type=="operator")
            {
                if(equation.operatorType!="IteratorOp"&&equation.operatorType!="PartialIteratorOp"&&equation.operatorType!="OpCall")
                {
                    equation.width=70;
                    equation.height=84;

                    if(equation.operatorType=="IfThenElseOp"||equation.operatorType=="CaseOp")
                    {
                        equation.width=70;
                        equation.height=84;
                    }
                }
                else
                {
                    equation.width=120;
                    equation.height=134;
                }

                //获取操作符端口
                parseEquationPorts(equation);

            }

            diagram.equations[j]=equation;
        }

        //移除所有需要移除的图元，如结束符和REDACE不支持的操作符
        for(int i=equationDelIndex.size()-1;i>=0;i--)
        {
            diagram.equations.removeAt(equationDelIndex.at(i));
        }

        QList<int> lineDelIndex;//需要移除的连接线的下标

        //处理连接线，获取连接线起点和终点
        for(int j=0;j<diagram.lineList.size();j++)
        {
            Line line;
            line=diagram.lineList.at(j);

            line.id=EleID;
            datas.diagrams[i].lineList[j].id=EleID;

            //            EleID=EleID+2*datas.diagrams[i].lineList[j].lineLengthList.size()+1;

            //连接线左右图元
            Equation leftEquation;
            Equation rightEquation;

            for(int k=0;k<diagram.equations.size();k++)
            {
                if(diagram.equations.at(k).oid==line.leftEquationOid)
                    leftEquation=diagram.equations.at(k);

                if(diagram.equations.at(k).oid==line.rightEquationOid)
                {
                    rightEquation=diagram.equations.at(k);
                    //                    diagram.equations[k].linkId=EleID-1;
                }
            }

            //连接线的左或右端的图元找不到时
            if(rightEquation.type.isEmpty()||leftEquation.type.isEmpty())
            {
                lineDelIndex.append(j);
                //                diagram.lineList.removeAt(j);
                continue;
            }

            if(!rightEquation.rightList.isEmpty()){
            if(rightEquation.rightList.at(line.rightIndex.toInt()-1).type=="if"||rightEquation.rightList.at(line.rightIndex.toInt()-1).type=="para")
            {
                EleID=EleID+2*datas.diagrams[i].lineList[j].lineLengthList.size();
            }
            else {
                EleID=EleID+2*datas.diagrams[i].lineList[j].lineLengthList.size()+1;
            }
            }

            if(!leftEquation.outList.isEmpty()){
            //连接线起点
            line.beginX=leftEquation.outList.at(line.leftIndex.toInt()-1).x;
            line.beginY=leftEquation.outList.at(line.leftIndex.toInt()-1).y;
            }

            if(!rightEquation.rightList.isEmpty())
            {
            //连接线终点
            line.endX=rightEquation.rightList.at(line.rightIndex.toInt()-1).x;
            line.endY=rightEquation.rightList.at(line.rightIndex.toInt()-1).y;

            rightEquation.rightList[line.rightIndex.toInt()-1].linkLine=line;
            }

            if(!diagram.equations.isEmpty()){
            for(int k=0;k<diagram.equations.size();k++)
            {
                if(diagram.equations.at(k).oid==rightEquation.oid)
                {
                    diagram.equations[k]=rightEquation;//保存rightEquation
                }
            }
            }


            //处理连接线的长度
            int hSum;
            int zSum;
            if(!rightEquation.rightList.isEmpty()){
            if(rightEquation.rightList.at(line.rightIndex.toInt()-1).type=="if"||rightEquation.rightList.at(line.rightIndex.toInt()-1).type=="para")
            {
                hSum=line.endX-line.beginX+5;
                zSum=line.endY-line.beginY-5;
            }
            else
            {
                hSum=line.endX-line.beginX;
                zSum=line.endY-line.beginY;
            }
            }


            if(!line.lineLengthList.isEmpty()){
            for(int k=0;k<line.lineLengthList.size();k++)
            {
                LineLength lineLength=line.lineLengthList.at(k);
                if(!rightEquation.rightList.isEmpty())
                {

                if(rightEquation.rightList.at(line.rightIndex.toInt()-1).type=="if"||rightEquation.rightList.at(line.rightIndex.toInt()-1).type=="para")
                {
                    if(k!=(line.lineLengthList.size()-1))
                    {
                        lineLength.hLength=lineLength.hLength/ZOOM;
                        lineLength.zLength=lineLength.zLength/ZOOM;
                        hSum=hSum-lineLength.hLength;
                        zSum=zSum-lineLength.zLength;
                    }
                    else {
                        lineLength.hLength=hSum;
                        lineLength.zLength=zSum;
                    }
                }
                else
                {

                    if(k!=(line.lineLengthList.size()-1))
                    {
                        lineLength.hLength=lineLength.hLength/ZOOM;
                        lineLength.zLength=lineLength.zLength/ZOOM;
                        zSum=zSum-lineLength.zLength;
                    }
                    else
                    {
                        lineLength.hLength=lineLength.hLength/ZOOM;
                        lineLength.zLength=zSum;
                    }
                }

                }
                line.lineLengthList[k]=lineLength;
            }
            }

            diagram.lineList[j]=line;
        }

        //删除需要删除的线
        for(int i=lineDelIndex.size()-1;i>=0;i--)
        {
            diagram.lineList.removeAt(lineDelIndex.at(i));
        }

        datas.diagrams[i]=diagram;
    }
}

void OperatorImporter::parseEquationPorts(Equation &data)
{
    //一元操作符
    if(data.operatorType=="UnaryOp")
        parseUnaryOpPorts(data);

    //二元操作符
    if(data.operatorType=="BinaryOp")
        parseBinaryOpPorts(data);

    //多元操作符
    if(data.operatorType=="NAryOp")
        parseNAryOpPorts(data);

    //Previous
    if(data.operatorType=="PreOp")
        parsePreOpPorts(data);

    //Init
    if(data.operatorType=="InitOp")
        parseInitOpPorts(data);

    //Fby
    if(data.operatorType=="FbyOp")
        parseFbyOpPorts(data);

    //Prj
    if(data.operatorType=="PrjOp")
        parsePrjOpPorts(data);

    //Slice
    if(data.operatorType=="SliceOp")
        parseSliceOpPorts(data);

    //PrjDyn
    if(data.operatorType=="PrjDynOp")
        parsePrjDynOpPorts(data);

    //DataStruct
    if(data.operatorType=="DataStructOp")
        parseDataStructOpPorts(data);

    //ScalarToVector
    if(data.operatorType=="ScalarToVectorOp")
        parseScalarToVectorOpPorts(data);

    //DataArray
    if(data.operatorType=="DataArrayOp")
        parseDataArrayOpPorts(data);

    //ChgIthOp
    if(data.operatorType=="ChgIthOp")
        parseChgIthOpPorts(data);

    //IfThenElse
    if(data.operatorType=="IfThenElseOp")
        parseIfThenElseOpPorts(data);

    //Case
    if(data.operatorType=="CaseOp")
        parseCaseOpPorts(data);

    //Make
    if(data.operatorType=="MakeOp")
        parseMakeOpPorts(data);

    //Flatten
    if(data.operatorType=="FlattenOp")
        parseFlattenOpPorts(data);

    //Iterator
    if(data.operatorType=="IteratorOp")
        parseIteratorOpPorts(data);

    //PartialIterator
    if(data.operatorType=="PartialIteratorOp")
        parsePartialIteratorOpPorts(data);

    //OpCall
    if(data.operatorType=="OpCall")
        parseOpCallPorts(data);
}

void OperatorImporter::parseUnaryOpPorts(Equation &data)
{
    data.eleType="ELETYPE_OPERATOR";

    if(data.operatorName=="Unary Minus")
    {
        data.opeName="-";
        data.text="-";
    }

    if(data.operatorName=="Not")
    {
        data.opeName="not";
        data.text="not";
    }

    if(data.operatorName=="Convert To Integer")
    {
        data.opeName="INT";
        data.text="int";
    }

    if(data.operatorName=="Convert To Real")
    {
        data.opeName="REAL";
        data.text="real";
    }

    int gap=data.height/2;
    portCoordinate inport;
    inport.type="in";
    inport.x=data.x;
    inport.y=data.y+gap-5;
    data.inList.append(inport);

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+gap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
}

void OperatorImporter::parseBinaryOpPorts(Equation &data)
{
    data.eleType="ELETYPE_OPERATOR";

    if(data.operatorName=="Minus")
    {
        data.opeName="+-";
        data.text="-";
    }

    if(data.operatorName=="Polymorphic Division")
    {
        data.opeName="/";
        data.text="/";
    }

    if(data.operatorName=="Integer Division")
    {
        data.opeName="div";
        data.text="div";
    }

    if(data.operatorName=="Modulo")
    {
        data.opeName="MOD";
        data.text="mod";
    }

    if(data.operatorName=="Strictly Less Than")
    {
        data.opeName="<";
        data.text="<";
    }

    if(data.operatorName=="Less Than Or Equal")
    {
        data.opeName="<=";
        data.text="<=";
    }

    if(data.operatorName=="Strictly Greater Than")
    {
        data.opeName=">";
        data.text=">";
    }

    if(data.operatorName=="Greater Than Or Equal")
    {
        data.opeName=">=";
        data.text=">=";
    }

    if(data.operatorName=="Different")
    {
        data.opeName="<>";
        data.text="<>";
    }

    if(data.operatorName=="Equal")
    {
        data.opeName="=";
        data.text="=";
    }

    int lgap=data.height/3;
    int rgap=data.height/2;
    for(int i=0;i<2;i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+rgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
}

void OperatorImporter::parseNAryOpPorts(Equation &data)
{
    data.eleType="ELETYPE_OPERATOR";

    if(data.operatorName=="Plus")
    {
        data.opeName="++";
        data.text="+";
    }

    if(data.operatorName=="Multiplication")
    {
        data.opeName="*";
        data.text="*";
    }

    if(data.operatorName=="And")
    {
        data.opeName="and";
        data.text="and";
    }

    if(data.operatorName=="Or")
    {
        data.opeName="or";
        data.text="or";
    }

    if(data.operatorName=="Exclusive Or")
    {
        data.opeName="xor";
        data.text="xor";
    }


    int lgap=data.height/(data.nAryOp.constVarRefs.size()+1);
    int rgap=data.height/2;
    for(int i=0;i<data.nAryOp.constVarRefs.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+rgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
}

void OperatorImporter::parsePreOpPorts(Equation &data)
{
    data.eleType="ELETYPE_TIME";

    data.opeName="PreOp";
    data.text="";

    int gap=data.height/(data.lefts.size()+1);
    for(int i=0;i<data.preOp.flows.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+gap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+gap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.inList);

}

void OperatorImporter::parseInitOpPorts(Equation &data)
{
    data.eleType="ELETYPE_TIME";

    data.opeName="InitOp";
    data.text="";

    int zgap=data.height/(data.lefts.size()+1);
    int hgap=data.width/(data.lefts.size()+1);

    for(int i=0;i<data.initOp.flows.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+zgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<data.initOp.parameters.size();i++)
    {
        portCoordinate paraport;
        paraport.type="para";

        paraport.paraValue=data.initOp.parameters.at(i).value;

        paraport.x=data.x+hgap*(i+1)-5;
        paraport.y=data.y+data.height;
        data.paraList.append(paraport);
    }

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+zgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseFbyOpPorts(Equation &data)
{
    data.eleType="ELETYPE_TIME";

    data.opeName="FbyOp";
    data.text="";

    int zgap=data.height/(data.lefts.size()+1);
    int hgap=data.width/(data.fbyOp.parameters.size()+2);

    for(int i=0;i<data.fbyOp.flows.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+zgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<(data.fbyOp.parameters.size()+1);i++)
    {
        portCoordinate paraport;
        paraport.type="para";
        if(i==0)
        {
            paraport.paraValue=data.fbyOp.delay.value;
        }
        else
        {
            paraport.paraValue=data.fbyOp.parameters.at(i-1).value;

        }

        paraport.x=data.x+hgap*(i+1)-5;
        paraport.y=data.y+data.height;
        data.paraList.append(paraport);
    }

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+zgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parsePrjOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="PrjOp";
    data.text="";

    int zgap=data.height/2;
    int hgap=data.width/(data.prjOp.parameters.size()+1);

    portCoordinate inport;
    inport.type="in";
    inport.x=data.x;
    inport.y=data.y+zgap-5;
    data.inList.append(inport);

    for(int i=0;i<data.prjOp.parameters.size();i++)
    {
        portCoordinate paraport;
        paraport.type="para";
        paraport.paraValue=data.prjOp.parameters.at(i).value;

        paraport.x=data.x+hgap*(i+1)-5;
        paraport.y=data.y+data.height;
        data.paraList.append(paraport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+zgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseSliceOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="SliceOp";
    data.text="";

    int zgap=data.height/2;
    int hgap=data.width/3;

    portCoordinate inport;
    inport.type="in";
    inport.x=data.x;
    inport.y=data.y+zgap-5;
    data.inList.append(inport);

    for(int i=0;i<2;i++)
    {
        portCoordinate paraport;
        paraport.type="para";
        if(i==0)
        {
            paraport.paraValue=data.sliceOp.fromIndex.value;
        }
        else {
            paraport.paraValue=data.sliceOp.toIndex.value;
        }

        paraport.x=data.x+hgap*(i+1)-5;
        paraport.y=data.y+data.height;
        data.paraList.append(paraport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+zgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parsePrjDynOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="PrjDynOp";
    data.text="";

    int zgap=data.height/2;
    int hgap=data.width/(data.prjDynOp.indexes.size()+2);

    portCoordinate inport;
    inport.type="in";
    inport.x=data.x;
    inport.y=data.y+zgap-5;
    data.inList.append(inport);

    for(int i=0;i<(data.prjDynOp.indexes.size()+1);i++)
    {
        portCoordinate paraport;
        paraport.type="para";

        if(i!=data.prjDynOp.indexes.size())
        {
            paraport.paraValue=data.prjDynOp.indexes.at(i).value;
        }
        else {
            paraport.paraValue=data.prjDynOp.defaultpara.value;
        }

        paraport.x=data.x+hgap*(i+1)-5;
        paraport.y=data.y+data.height;
        data.paraList.append(paraport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+zgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseDataStructOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="DataStructOp";
    data.text="";

    int lgap=data.height/(data.dataStructOp.labels.size()+1);
    int rgap=data.height/2;

    for(int i=0;i<data.dataStructOp.labels.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<data.dataStructOp.labels.size();i++)
    {
        portCoordinate paraport;
        paraport.type="para";
        paraport.paraValue=data.dataStructOp.labels.at(i).labelName;

        paraport.x=data.x;
        paraport.y=data.y+lgap*(i+1)-5;
        data.paraList.append(paraport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+rgap-5;
    data.outList.append(outport);


    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseScalarToVectorOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="ScalarToVectorOp";
    data.text="";

    int zgap=data.height/(data.lefts.size()+1);
    int hgap=data.width/2;

    for(int i=0;i<data.scalarToVectorOp.flows.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+zgap*(i+1)-5;
        data.inList.append(inport);
    }

    portCoordinate paraport;
    paraport.type="para";
    paraport.paraValue=data.scalarToVectorOp.size.value;

    paraport.x=data.x+hgap-5;
    paraport.y=data.y+data.height;
    data.paraList.append(paraport);

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+zgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);

}

void OperatorImporter::parseDataArrayOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="DataArrayOp";
    data.text="";

    int lgap=data.height/(data.dataArrayOp.datas.size()+1);
    int rgap=data.height/2;

    for(int i=0;i<data.dataArrayOp.datas.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+rgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
}

void OperatorImporter::parseChgIthOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="ChgIthOp";
    data.text="";

    int lgap=data.height/3;
    int hgap=data.width/(data.chgIthOp.parameters.size()+1);
    int rgap=data.height/2;

    for(int i=0;i<2;i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<data.chgIthOp.parameters.size();i++)
    {
        portCoordinate paraport;
        paraport.type="para";
        paraport.paraValue=data.chgIthOp.parameters.at(i).value;

        paraport.x=data.x+hgap*(i+1)-5;
        paraport.y=data.y+data.height;
        data.paraList.append(paraport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+rgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseIfThenElseOpPorts(Equation &data)
{
    data.eleType="ELETYPE_CHOICE";

    data.opeName="IfThenElseOp";
    data.text="";

    int hgap=data.width/2;
    int lgap=data.height/(data.ifThenElseOp.thens.size()+data.ifThenElseOp.elses.size()+1);
    int rgap=data.height/(data.ifThenElseOp.thens.size()+1);

    portCoordinate ifport;
    ifport.type="if";
    ifport.x=data.x+hgap-5;
    ifport.y=data.y;
    data.ifList.append(ifport);

    for(int i=0;i<(data.ifThenElseOp.thens.size()+data.ifThenElseOp.elses.size());i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }


    for(int i=0;i<data.ifThenElseOp.thens.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+rgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.ifList);
    data.rightList.append(data.inList);
}

void OperatorImporter::parseCaseOpPorts(Equation &data)
{
    data.eleType="ELETYPE_CHOICE";

    data.opeName="CaseOp";
    data.text="";

    int hgap=data.width/2;
    int lgap=data.height/(data.caseOp.cases.size()+2);
    int rgap=data.height/2;

    portCoordinate ifport;
    ifport.type="if";
    ifport.x=data.x+hgap-5;
    ifport.y=data.y;
    data.ifList.append(ifport);

    for(int i=0;i<(data.caseOp.cases.size()+1);i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<(data.caseOp.cases.size()+1);i++)
    {
        portCoordinate paraport;
        paraport.type="para";
        if(i!=data.caseOp.cases.size())
        {
            paraport.paraValue=data.caseOp.cases.at(i).labelName;
        }
        else
        {
            paraport.paraValue="Default";
        }

        paraport.x=data.x;
        paraport.y=data.y+lgap*(i+1)-5;
        data.paraList.append(paraport);
    }

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+rgap-5;
    data.outList.append(outport);

    data.rightList.append(data.ifList);
    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseMakeOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="MakeOp";
    data.text="";

    int lgap=data.height/(data.makeOp.calls.size()+1);
    int rgap=data.height/2;
    int hgap=data.width/2;

    for(int i=0;i<data.makeOp.calls.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    portCoordinate paraport;
    paraport.type="para";
    paraport.paraValue=data.makeOp.typeRef;

    paraport.x=data.x+hgap-5;
    paraport.y=data.y+data.height;
    data.paraList.append(paraport);

    portCoordinate outport;
    outport.type="out";
    outport.x=data.x+data.width;
    outport.y=data.y+rgap-5;
    data.outList.append(outport);

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseFlattenOpPorts(Equation &data)
{
    data.eleType="ELETYPE_STRUCTURE";

    data.opeName="FlattenOp";
    data.text="";

    int lgap=data.height/2;
    int rgap=data.height/(data.lefts.size()+1);
    int hgap=data.width/2;

    portCoordinate inport;
    inport.type="in";
    inport.x=data.x;
    inport.y=data.y+lgap-5;
    data.inList.append(inport);

    portCoordinate paraport;
    paraport.type="para";
    paraport.paraValue=data.flattenOp.typeRef;

    paraport.x=data.x+hgap-5;
    paraport.y=data.y+data.height;
    data.paraList.append(paraport);

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+rgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.inList);
    data.rightList.append(data.paraList);
}

void OperatorImporter::parseIteratorOpPorts(Equation &data)
{

    data.eleType="ELETYPE_HIGHER";
    data.opeName=data.iteratorOp.iteratorType;
    data.text=data.iteratorOp.size.value;

    //Unary Minus取反运算
    if(data.iteratorOp.operatorRef=="-$")
    {
        data.iteratorOp.usedIdName="-";
        data.iteratorOp.refName="-";
    }

    //Not非运算
    if(data.iteratorOp.operatorRef=="not$")
    {
        data.iteratorOp.usedIdName="not";
        data.iteratorOp.refName="not";
    }

    //Convert To Integer强制转换为整数运算
    if(data.iteratorOp.operatorRef=="int$")
    {
        data.iteratorOp.usedIdName="INT";
        data.iteratorOp.refName="int";
    }

    //Convert To Real强制转换换浮点数运算
    if(data.iteratorOp.operatorRef=="real$")
    {
        data.iteratorOp.usedIdName="REAL";
        data.iteratorOp.refName="real";
    }

    //Minus 减法运算
    if(data.iteratorOp.operatorRef=="$-$")
    {
        data.iteratorOp.usedIdName="+-";
        data.iteratorOp.refName="-";
    }

    //Polymorphic Division 除法运算（输出值为浮点数）
    if(data.iteratorOp.operatorRef=="$/$")
    {
        data.iteratorOp.usedIdName="/";
        data.iteratorOp.refName="/";
    }

    //Integer Division 除法运算（输出值为整数）
    if(data.iteratorOp.operatorRef=="$div$")
    {
        data.iteratorOp.usedIdName="div";
        data.iteratorOp.refName="div";
    }

    //Modulo 求余运算
    if(data.iteratorOp.operatorRef=="$mod$")
    {
        data.iteratorOp.usedIdName="MOD";
        data.iteratorOp.refName="mod";
    }

    //Strictly Less Than  <
    if(data.iteratorOp.operatorRef=="$<$")
    {
        data.iteratorOp.usedIdName="<";
        data.iteratorOp.refName="<";
    }

    //Less Than Or Equal   <=
    if(data.iteratorOp.operatorRef=="$<=$")
    {
        data.iteratorOp.usedIdName="<=";
        data.iteratorOp.refName="<=";
    }

    //Strictly Greater Than  >
    if(data.iteratorOp.operatorRef=="$>$")
    {
        data.iteratorOp.usedIdName=">";
        data.iteratorOp.refName=">";
    }

    //Greater Than Or Equal   >=
    if(data.iteratorOp.operatorRef=="$>=$")
    {
        data.iteratorOp.usedIdName=">=";
        data.iteratorOp.refName=">=";
    }

    //Different  !=
    if(data.iteratorOp.operatorRef=="$<>$")
    {
        data.iteratorOp.usedIdName="<>";
        data.iteratorOp.refName="<>";
    }

    //Equal    ==
    if(data.iteratorOp.operatorRef=="$=$")
    {
        data.iteratorOp.usedIdName="=";
        data.iteratorOp.refName="=";
    }

    //Plus加法运算
    if(data.iteratorOp.operatorRef=="$+$")
    {
        data.iteratorOp.usedIdName="++";
        data.iteratorOp.refName="+";
    }

    //Multiplication乘法运算
    if(data.iteratorOp.operatorRef=="$*$")
    {
        data.iteratorOp.usedIdName="*";
        data.iteratorOp.refName="*";
    }

    //And 与运算
    if(data.iteratorOp.operatorRef=="$and$")
    {
        data.iteratorOp.usedIdName="and";
        data.iteratorOp.refName="and";
    }

    //Or 或运算
    if(data.iteratorOp.operatorRef=="$or$")
    {
        data.iteratorOp.usedIdName="or";
        data.iteratorOp.refName="or";
    }

    //Exclusive Or异或运算
    if(data.iteratorOp.operatorRef=="$xor$")
    {
        data.iteratorOp.usedIdName="xor";
        data.iteratorOp.refName="xor";
    }

    //自定义操作符
    if(data.iteratorOp.isRef==true)
    {
        data.iteratorOp.usedIdName=data.iteratorOp.operatorRef;
        data.iteratorOp.refName=data.iteratorOp.operatorRef;
    }

    int lgap=data.height/(data.iteratorOp.calls.size()+1);
    int rgap=data.height/(data.lefts.size()+1);

    for(int i=0;i<data.iteratorOp.calls.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+rgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.inList);
}

void OperatorImporter::parsePartialIteratorOpPorts(Equation &data)
{
    //由于不清楚REDACE的高阶嵌套规则，暂时只支持+嵌套
    data.eleType="ELETYPE_HIGHER";
    data.opeName=data.partialIteratorOp.partialIteratorType;
    data.text=data.partialIteratorOp.size.value;

    //Unary Minus取反运算
    if(data.partialIteratorOp.operatorRef=="-$")
    {
        data.partialIteratorOp.usedIdName="-";
        data.partialIteratorOp.refName="-";
    }

    //Not非运算
    if(data.partialIteratorOp.operatorRef=="not$")
    {
        data.partialIteratorOp.usedIdName="not";
        data.partialIteratorOp.refName="not";
    }

    //Convert To Integer强制转换为整数运算
    if(data.partialIteratorOp.operatorRef=="int$")
    {
        data.partialIteratorOp.usedIdName="INT";
        data.partialIteratorOp.refName="int";
    }

    //Convert To Real强制转换换浮点数运算
    if(data.partialIteratorOp.operatorRef=="real$")
    {
        data.partialIteratorOp.usedIdName="REAL";
        data.partialIteratorOp.refName="real";
    }

    //Minus 减法运算
    if(data.partialIteratorOp.operatorRef=="$-$")
    {
        data.partialIteratorOp.usedIdName="+-";
        data.partialIteratorOp.refName="-";
    }

    //Polymorphic Division 除法运算（输出值为浮点数）
    if(data.partialIteratorOp.operatorRef=="$/$")
    {
        data.partialIteratorOp.usedIdName="/";
        data.partialIteratorOp.refName="/";
    }

    //Integer Division 除法运算（输出值为整数）
    if(data.partialIteratorOp.operatorRef=="$div$")
    {
        data.partialIteratorOp.usedIdName="div";
        data.partialIteratorOp.refName="div";
    }

    //Modulo 求余运算
    if(data.partialIteratorOp.operatorRef=="$mod$")
    {
        data.partialIteratorOp.usedIdName="MOD";
        data.partialIteratorOp.refName="mod";
    }

    //Strictly Less Than  <
    if(data.partialIteratorOp.operatorRef=="$<$")
    {
        data.partialIteratorOp.usedIdName="<";
        data.partialIteratorOp.refName="<";
    }

    //Less Than Or Equal   <=
    if(data.partialIteratorOp.operatorRef=="$<=$")
    {
        data.partialIteratorOp.usedIdName="<=";
        data.partialIteratorOp.refName="<=";
    }

    //Strictly Greater Than  >
    if(data.partialIteratorOp.operatorRef=="$>$")
    {
        data.partialIteratorOp.usedIdName=">";
        data.partialIteratorOp.refName=">";
    }

    //Greater Than Or Equal   >=
    if(data.partialIteratorOp.operatorRef=="$>=$")
    {
        data.partialIteratorOp.usedIdName=">=";
        data.partialIteratorOp.refName=">=";
    }

    //Different  !=
    if(data.partialIteratorOp.operatorRef=="$<>$")
    {
        data.partialIteratorOp.usedIdName="<>";
        data.partialIteratorOp.refName="<>";
    }

    //Equal    ==
    if(data.partialIteratorOp.operatorRef=="$=$")
    {
        data.partialIteratorOp.usedIdName="=";
        data.partialIteratorOp.refName="=";
    }

    //Plus加法运算
    if(data.partialIteratorOp.operatorRef=="$+$")
    {
        data.partialIteratorOp.usedIdName="++";
        data.partialIteratorOp.refName="+";
    }

    //Multiplication乘法运算
    if(data.partialIteratorOp.operatorRef=="$*$")
    {
        data.partialIteratorOp.usedIdName="*";
        data.partialIteratorOp.refName="*";
    }

    //And 与运算
    if(data.partialIteratorOp.operatorRef=="$and$")
    {
        data.partialIteratorOp.usedIdName="and";
        data.partialIteratorOp.refName="and";
    }

    //Or 或运算
    if(data.partialIteratorOp.operatorRef=="$or$")
    {
        data.partialIteratorOp.usedIdName="or";
        data.partialIteratorOp.refName="or";
    }

    //Exclusive Or异或运算
    if(data.partialIteratorOp.operatorRef=="$xor$")
    {
        data.partialIteratorOp.usedIdName="xor";
        data.partialIteratorOp.refName="xor";
    }

    //自定义操作符
    if(data.partialIteratorOp.isRef==true)
    {
        data.partialIteratorOp.usedIdName=data.partialIteratorOp.operatorRef;
        data.partialIteratorOp.refName=data.partialIteratorOp.operatorRef;
    }


    int hgap=data.width/2;
    int lgap=data.height/(data.partialIteratorOp.calls.size()+1);
    int rgap=data.height/(data.lefts.size()+1);

    portCoordinate ifport;
    ifport.type="if";
    ifport.x=data.x+hgap-5;
    ifport.y=data.y;
    data.ifList.append(ifport);

    for(int i=0;i<data.partialIteratorOp.calls.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+rgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.ifList);
    data.rightList.append(data.inList);

    if(data.partialIteratorOp.hasDefault==true)
    {
        portCoordinate paraport;
        paraport.type="para";
        paraport.paraValue=data.partialIteratorOp.defaultValue.value;

        paraport.x=data.x+hgap-5;
        paraport.y=data.y+data.height;
        data.paraList.append(paraport);

        data.rightList.append(data.paraList);
    }

}

void OperatorImporter::parseOpCallPorts(Equation &data)
{
    data.eleType="ELETYPE_CUST_OPE";
    data.opeName=data.opCall.operatorRef;

    if(data.opeName.contains("::"))
    {
        QStringList list=data.opeName.split("::");

        data.opeName=list.at(list.size()-1);
    }

    data.text="";

    //目前只支持无参数和if的操作符引用
    int lgap=data.height/(data.opCall.calls.size()+1);
    int rgap=data.height/(data.lefts.size()+1);

    for(int i=0;i<data.opCall.calls.size();i++)
    {
        portCoordinate inport;
        inport.type="in";
        inport.x=data.x;
        inport.y=data.y+lgap*(i+1)-5;
        data.inList.append(inport);
    }

    for(int i=0;i<data.lefts.size();i++)
    {
        portCoordinate outport;
        outport.type="out";
        outport.x=data.x+data.width;
        outport.y=data.y+rgap*(i+1)-5;
        data.outList.append(outport);
    }

    data.rightList.append(data.inList);
}

void OperatorImporter::saveOperatorFile(const QString &redaceProjectPath,const QString &scadeProjectName,const QString &operatorFileName,OperatorData &datas)
{
    QString filePath=redaceProjectPath+"/"+scadeProjectName+"/"+operatorFileName;
    QFile file(filePath);
    QFileInfo fileInfo=QFileInfo(filePath);

    if(!file.open(QFile::WriteOnly|QFile::Truncate))
        return;

    QXmlStreamWriter writer(&file);

    writer.setAutoFormatting(true);
    writer.setAutoFormattingIndent(2);

    //写入StartDocument
    writer.writeStartDocument();

    //写File节点
    writer.writeStartElement("File");
    writer.writeAttribute("Type","Operator");

    //declarations
    writer.writeStartElement("declarations");

    //Operator
    writer.writeStartElement("Operator");
    writer.writeAttribute("kind",datas.kind);

    if(datas.isImported==true)
        writer.writeAttribute("external","imported");

    writer.writeAttribute("name",datas.operatorName);

    //operator_property
    writer.writeStartElement("operator_property");
    writer.writeAttribute("description",datas.comment);
    writer.writeAttribute("subFolderName","");
    writer.writeAttribute("isInSubFolder","False");

    if(datas.isImported==false)
    {
        writer.writeAttribute("isImportOpe","false");
        writer.writeAttribute("cFilePath","");
        writer.writeAttribute("hFilePath","");
    }
    else
    {
        writer.writeAttribute("isImportOpe","true");
        writer.writeAttribute("cFilePath",datas.cFilePath);
        writer.writeAttribute("hFilePath","");
    }


    writer.writeAttribute("stylePath","");
    writer.writeEndElement();//结束operator_property

    //inputs
    bool hasInput=false;
    for(int i=0;i<datas.variables.size();i++)
    {
        if(datas.variables.at(i).type=="input")
        {
            hasInput=true;
        }
    }
    if(hasInput==true)
    {
        writer.writeStartElement("inputs");
        for(int i=0;i<datas.variables.size();i++)
        {
            if(datas.variables.at(i).type=="input")
            {
                saveVariable(writer,datas.variables.at(i));
            }
        }

        writer.writeEndElement();
    }


    //outputs
    bool hasOutput=false;
    for(int i=0;i<datas.variables.size();i++)
    {
        if(datas.variables.at(i).type=="output")
        {
            hasOutput=true;
        }
    }
    if(hasOutput==true)
    {
        writer.writeStartElement("outputs");
        for(int i=0;i<datas.variables.size();i++)
        {
            if(datas.variables.at(i).type=="output")
            {
                saveVariable(writer,datas.variables.at(i));
            }
        }

        writer.writeEndElement();
    }

    //locals
    bool hasLocal=false;
    for(int i=0;i<datas.variables.size();i++)
    {
        if(datas.variables.at(i).type=="local")
        {
            hasLocal=true;
        }
    }
    if(hasLocal==true)
    {
        writer.writeStartElement("locals");
        for(int i=0;i<datas.variables.size();i++)
        {
            if(datas.variables.at(i).type=="local")
            {
                saveVariable(writer,datas.variables.at(i));
            }
        }

        writer.writeEndElement();
    }

    //data
    if(!datas.equations.isEmpty())
    {
        writer.writeStartElement("data");
        for(int i=0;i<datas.equations.size();i++)
        {
            saveEquation(writer,datas.equations.at(i));
        }
        writer.writeEndElement();
    }

    //oid
    writer.writeStartElement("oid");
    writer.writeAttribute("value",datas.oid);
    writer.writeEndElement();//结束oid

    //diagrams
    if(!datas.diagrams.isEmpty())
    {
        writer.writeStartElement("diagrams");
        for(int i=0;i<datas.diagrams.size();i++)
        {
            writer.writeStartElement("NetDiagram");
            writer.writeAttribute("name",datas.diagrams.at(i).name);
            writer.writeAttribute("landscape",datas.diagrams.at(i).landscape);
            writer.writeAttribute("oid",datas.diagrams.at(i).redaceOid);
            writer.writeAttribute("EleIDIndex","");
            writer.writeAttribute("OutPortIndex","");
            writer.writeAttribute("ProjectName","");
            writer.writeAttribute("DiagramName","");
            writer.writeAttribute("DiagramId","");
            writer.writeAttribute("Description","");
            writer.writeAttribute("DiagramNum","");
            writer.writeAttribute("DiagramVersion","");
            writer.writeAttribute("DesignPersonName","");
            writer.writeAttribute("DesignTime","");
            writer.writeAttribute("CheckPersonName","");
            writer.writeAttribute("CheckTime","");
            writer.writeAttribute("DeterminePersonName","");
            writer.writeAttribute("DetermineTime","");
            writer.writeAttribute("ApprovePersonName","");
            writer.writeAttribute("ApproveTime","");
            writer.writeAttribute("FDDiagram","False");
            writer.writeAttribute("BackgroundImageWidth","0");
            writer.writeAttribute("BackgroundImageHeight","0");
            writer.writeAttribute("BackgroundImageFileName","");

            writer.writeEndElement();
        }
        writer.writeEndElement();
    }


    writer.writeEndElement();//结束data

    writer.writeEndElement();//结束Operator

    writer.writeEndElement();//结束declarations

    writer.writeEndElement();//结束File

    writer.writeEndDocument();

    file.close();

}

void OperatorImporter::saveDiagramFile(const QString &filePath,OperatorData &datas)
{
    QString pousDirName=filePath+"/"+"POUs";//POUs文件夹
    QDir poudir(pousDirName);
    if(!poudir.exists())
        poudir.mkdir(pousDirName);//创建POUs文件夹

    //创建操作符文件夹
    QString operatorDir=pousDirName+"/"+datas.operatorName;
    QDir opedir(operatorDir);
    if(!opedir.exists())
        opedir.mkdir(operatorDir);

    //    int EleID=0;

    for(int i=0;i<datas.diagrams.size();i++)
    {
        int eleIDIndex=0;
        int outPortIndex=1;

        QFile file(operatorDir+"/"+datas.diagrams.at(i).name);
        QFileInfo fileInfo=QFileInfo(operatorDir+"/"+datas.diagrams.at(i).name);

        if(!file.open(QFile::WriteOnly|QFile::Truncate))
            return;

        QXmlStreamWriter writer(&file);

        //presentationElements
        writer.writeStartElement("presentationElements");

        //生成图元
        saveEquationGE(writer,i,datas,eleIDIndex,outPortIndex);

        //生成连接线
        saveLineGE(writer,i,datas,eleIDIndex);

        writer.writeEndElement();


        file.close();

        //校正操作符文件中的算法页面的EleIDIndex和OutPortIndex值
        QFile opeFile(filePath+"/"+datas.operatorFileName);

        QString strAll;
        QStringList strList;

        if(opeFile.open(QIODevice::ReadOnly|QIODevice::Text))
        {
            QTextStream stream(&opeFile);
            stream.setCodec("UTF-8");
            strAll=stream.readAll();
        }

        opeFile.close();

        if(opeFile.open(QIODevice::WriteOnly|QIODevice::Text))
        {
            QTextStream stream(&opeFile);
            stream.setCodec("utf-8");
            strList=strAll.split("\n");

            for(int j=0;j<strList.size();j++)
            {
                if(strList.at(j).contains("name=\""+datas.diagrams.at(i).name+"\""))
                {
                    strList[j].replace("EleIDIndex=\"\"","EleIDIndex=\""+QString("%1").arg(eleIDIndex)+"\"");
                    strList[j].replace("OutPortIndex=\"\"","OutPortIndex=\""+QString("%1").arg(outPortIndex)+"\"");
                }

                stream<<strList.at(j)<<endl;
            }

        }

        opeFile.close();
    }
}

void OperatorImporter::saveEquationGE(QXmlStreamWriter &writer,const int &i,OperatorData &datas,int &eleIDindex,int &outPortIndex)
{
    for(int j=0;j<datas.diagrams.at(i).equations.size();j++)
    {
        Equation equation=datas.diagrams.at(i).equations.at(j);

        if(equation.id>=eleIDindex)
        {
            eleIDindex=equation.id+1;
        }

        writer.writeStartElement("EquationGE");
        writer.writeAttribute("EleID",QString("%1").arg(equation.id));//EleID
        writer.writeAttribute("presentable",QUuid::createUuid().toString(QUuid::WithoutBraces));//oid

        writer.writeAttribute("EleType",equation.eleType);
        writer.writeAttribute("OpeName",equation.opeName);
        if(equation.operatorType=="OpCall")
        {
            writer.writeAttribute("CustomOpeSerialNumber",QUuid::createUuid().toString(QUuid::WithoutBraces));
        }

        //消除立即数中用到的常量含::的包路径
        if(equation.eleType=="ELETYPE_IMMEDIATE"&&equation.text.contains("::"))
        {
            // 分割字符串，跳过空部分
            QStringList parts = equation.text.split(' ', QString::SkipEmptyParts);
            QStringList processedParts;

            for (const QString &part : parts) {
                // 查找最后一个 "::" 的位置
                int lastIndex = part.lastIndexOf("::");
                QString newPart = part;

                if (lastIndex != -1) {
                    newPart = part.mid(lastIndex + 2); // 截取最后一个 "::" 之后的内容
                }

                // 过滤空字符串
                if (!newPart.isEmpty()) {
                    processedParts.append(newPart);
                }
            }

            // 重新用空格拼接处理后的子字符串
            equation.text=processedParts.join(" ");

            writer.writeAttribute("Text",equation.text);
        }
        else
        {
            writer.writeAttribute("Text",equation.text);
        }

        writer.writeAttribute("Instance","");

        if(equation.operatorType!="IteratorOp"&&equation.operatorType!="PartialIteratorOp")
        {
            writer.writeAttribute("UsedIdName","");
            writer.writeAttribute("RefName","");
        }

        if(equation.operatorType=="IteratorOp")
        {
            writer.writeAttribute("UsedIdName",equation.iteratorOp.usedIdName);
            writer.writeAttribute("RefName",equation.iteratorOp.refName);

            if(equation.iteratorOp.isRef==false)
            {
                writer.writeAttribute("IsRefOpe","False");
            }
            else {
                writer.writeAttribute("IsRefOpe","True");
            }

        }

        if(equation.operatorType=="PartialIteratorOp")
        {
            writer.writeAttribute("UsedIdName",equation.partialIteratorOp.usedIdName);
            writer.writeAttribute("RefName",equation.partialIteratorOp.refName);

            if(equation.partialIteratorOp.isRef==false)
            {
                writer.writeAttribute("IsRefOpe","False");
            }
            else {
                writer.writeAttribute("IsRefOpe","True");
            }

        }

        writer.writeAttribute("rcMode","");
        writer.writeAttribute("styleName","");
        writer.writeAttribute("Angle","0");
        writer.writeAttribute("FDOid","");
        writer.writeAttribute("ContainPageName","False");

        //comment
        writer.writeStartElement("comment");
        writer.writeStartElement("Comment");
        writer.writeAttribute("valueStr",equation.comment);
        writer.writeEndElement();
        writer.writeEndElement();

        //portNum
        writer.writeStartElement("portNum");
        writer.writeStartElement("Number");
        writer.writeAttribute("IfNum",QString("%1").arg(equation.ifList.size()));
        writer.writeAttribute("InNum",QString("%1").arg(equation.inList.size()));
        if(equation.operatorType=="DataStructOp"||equation.operatorType=="CaseOp")
        {
            writer.writeAttribute("ParaNum","0");
        }
        else {
            writer.writeAttribute("ParaNum",QString("%1").arg(equation.paraList.size()));
        }

        writer.writeAttribute("OutNum",QString("%1").arg(equation.outList.size()));
        writer.writeEndElement();
        writer.writeEndElement();

        //position
        writer.writeStartElement("position");
        writer.writeStartElement("Point");
        writer.writeAttribute("x",QString("%1").arg(equation.x));
        writer.writeAttribute("y",QString("%1").arg(equation.y));
        writer.writeEndElement();
        writer.writeEndElement();

        //size
        writer.writeStartElement("size");
        writer.writeStartElement("Size");
        writer.writeAttribute("width",QString("%1").arg(equation.width));
        writer.writeAttribute("height",QString("%1").arg(equation.height));
        writer.writeEndElement();
        writer.writeEndElement();


        //ifPort
        if(!equation.ifList.isEmpty())
        {
            writer.writeStartElement("ifPort");
            writer.writeAttribute("eleID",QString("%1").arg(equation.id));

            writer.writeAttribute("ifLinkId",QString("%1").arg(equation.rightList.at(0).linkLine.id+equation.rightList.at(0).linkLine.lineLengthList.size()*2-1));

            writer.writeEndElement();
        }

        //linkEleID        
        if(!equation.inList.isEmpty())
        {
            writer.writeStartElement("linkEleID");
            writer.writeAttribute("eleID",QString("%1").arg(equation.id));
            for(int k=0;k<equation.inList.size();k++)
            {
                if(!equation.rightList.at(equation.ifList.size()+k).linkLine.rightIndex.isEmpty())
                {
                    writer.writeStartElement("PortID");
                    writer.writeAttribute("linkIndex",QString("%1").arg(k));
                    writer.writeAttribute("linkPortIndex","0");
                    writer.writeAttribute("linkId",QString("%1").arg(equation.rightList.at(equation.ifList.size()+k).linkLine.id+equation.rightList.at(equation.ifList.size()+k).linkLine.lineLengthList.size()*2));

                    Equation leftEquation;
                    for(int n=0;n<m_operator.equations.size();n++)
                    {
                        if(m_operator.equations.at(n).oid==equation.rightList.at(equation.ifList.size()+k).linkLine.leftEquationOid)
                            leftEquation=m_operator.equations.at(n);
                    }
                    QString portDataType;

                    for(int n=0;n<m_operator.variables.size();n++)
                    {

                        if(m_operator.variables.at(n).name==leftEquation.lefts.at(equation.rightList.at(equation.ifList.size()+k).linkLine.leftIndex.toInt()-1))
                            portDataType=m_operator.variables.at(n).dataType;
                    }

                    //去掉portDataType中的包路径
                    if(portDataType.contains("::"))
                    {
                        int lastIndex = portDataType.lastIndexOf("::");
                        portDataType=(lastIndex == -1) ? portDataType : portDataType.mid(lastIndex + 2);
                    }

                    writer.writeAttribute("portDataType",portDataType);
                    writer.writeEndElement();
                }
            }

            writer.writeEndElement();
        }


        //paraPort
        if(!equation.paraList.isEmpty())
        {
            writer.writeStartElement("paraPort");
            writer.writeAttribute("eleID",QString("%1").arg(equation.id));
            for(int k=0;k<equation.paraList.size();k++)
            {
                writer.writeStartElement("ParaID");
                writer.writeAttribute("paraIndex",QString("%1").arg(k));

                //paraLinkId、value
                if(!equation.rightList.at(equation.ifList.size()+equation.inList.size()+k).linkLine.rightIndex.isEmpty())
                {
                    writer.writeAttribute("parLinkId",QString("%1").arg(equation.rightList.at(equation.ifList.size()+equation.inList.size()+k).linkLine.id+equation.rightList.at(equation.ifList.size()+equation.inList.size()+k).linkLine.lineLengthList.size()*2-1));

                    writer.writeAttribute("value","");
                }
                else
                {
                    QString paraValue=equation.rightList.at(equation.ifList.size()+equation.inList.size()+k).paraValue;

                    //去除操作符参数中的::包结构
                    if(paraValue.contains("::"))
                    {
                        int lastIndex = paraValue.lastIndexOf("::");
                        paraValue=(lastIndex == -1) ? paraValue : paraValue.mid(lastIndex + 2);
                    }

                    writer.writeAttribute("parLinkId","");
                    writer.writeAttribute("value",paraValue);

                }

                writer.writeEndElement();

            }

            writer.writeEndElement();

        }

        //outports
        if(!equation.outList.isEmpty())
        {
            writer.writeStartElement("outports");
            writer.writeAttribute("EleID",QString("%1").arg(equation.id));
            for(int k=0;k<equation.outList.size();k++)
            {
                writer.writeStartElement("outportID");
                writer.writeAttribute("outIndex",QString("%1").arg(k));
                writer.writeAttribute("localVarName",equation.lefts.at(k));
                writer.writeEndElement();

                if(equation.lefts.at(k).mid(2).toInt()>=outPortIndex)
                {
                    outPortIndex=equation.lefts.at(k).mid(2).toInt()+1;
                }
            }

            writer.writeEndElement();
        }


        writer.writeEndElement();

    }

}

void OperatorImporter::saveLineGE(QXmlStreamWriter &writer,const int &i,OperatorData &datas,int &eleIDindex)
{
    //连接线
    for(int j=0;j<datas.diagrams.at(i).lineList.size();j++)
    {
        Line line=datas.diagrams.at(i).lineList.at(j);
        //        line.id=EleID;
        //        datas.diagrams[i].lineList[j].id=EleID;

        int eleID=line.id;

        //连接线左右图元
        Equation leftEquation;
        Equation rightEquation;

        for(int k=0;k<datas.diagrams.at(i).equations.size();k++)
        {
            if(datas.diagrams.at(i).equations.at(k).oid==line.leftEquationOid)
                leftEquation=datas.diagrams.at(i).equations.at(k);

            if(datas.diagrams.at(i).equations.at(k).oid==line.rightEquationOid)
                rightEquation=datas.diagrams.at(i).equations.at(k);
        }

        //连接线起点
        int x=line.beginX;
        int y=line.beginY;

        for(int k=0;k<line.lineLengthList.size();k++)
        {
            LineLength lineLength=line.lineLengthList.at(k);

            for(int m=0;m<2;m++)
            {
                writer.writeStartElement("EquationGE");
                writer.writeAttribute("EleID",QString("%1").arg(eleID));//EleID
                writer.writeAttribute("presentable",QUuid::createUuid().toString(QUuid::WithoutBraces));//oid

                QString eleType="ELETYPE_LINE";
                //                QString ifNum="0";
                //                QString inNum="1";
                //                QString paraNum="0";
                //                QString outNum="1";

                writer.writeAttribute("EleType",eleType);
                writer.writeAttribute("OpeName","");
                writer.writeAttribute("Text","");
                writer.writeAttribute("Instance","");
                writer.writeAttribute("UsedIdName","");
                writer.writeAttribute("RefName","");

                //rcmode
                QString rcMode;
                if(m==0)
                {
                    if(lineLength.hLength>=0)
                        rcMode="HLINE";
                    else {
                        rcMode="HLINE_REV";
                    }
                }

                if(m==1)
                {
                    if(lineLength.zLength>=0)
                        rcMode="ZLINE";
                    else {
                        rcMode="ZLINE_REV";
                    }
                }

                writer.writeAttribute("rcMode",rcMode);
                writer.writeAttribute("Pattern","0");
                writer.writeAttribute("styleName","");
                writer.writeAttribute("Angle","0");
                writer.writeAttribute("FDOid","");
                writer.writeAttribute("ContainPageName","False");

                //comment
                writer.writeStartElement("comment");
                writer.writeStartElement("Comment");
                writer.writeAttribute("valueStr","");
                writer.writeEndElement();
                writer.writeEndElement();

                //portNum
                writer.writeStartElement("portNum");
                writer.writeStartElement("Number");
                writer.writeAttribute("IfNum","0");
                writer.writeAttribute("InNum","1");
                writer.writeAttribute("ParaNum","0");
                writer.writeAttribute("OutNum","1");
                writer.writeEndElement();
                writer.writeEndElement();

                //position
                writer.writeStartElement("position");
                writer.writeStartElement("Point");


                if(m==0)
                {
                    writer.writeAttribute("x",QString("%1").arg(x));
                    writer.writeAttribute("y",QString("%1").arg(y));

                    x=x+lineLength.hLength-5;
                    y=y+5;
                }

                if(m==1)
                {
                    writer.writeAttribute("x",QString("%1").arg(x));
                    writer.writeAttribute("y",QString("%1").arg(y));

                    x=x+5;
                    y=y+lineLength.zLength-5;
                }

                writer.writeEndElement();
                writer.writeEndElement();

                //size
                writer.writeStartElement("size");
                writer.writeStartElement("Size");

                if(m==0)
                {
                    writer.writeAttribute("width",QString("%1").arg(lineLength.hLength));
                    writer.writeAttribute("height",QString("%1").arg(10));
                }

                if(m==1)
                {
                    writer.writeAttribute("width",QString("%1").arg(10));
                    writer.writeAttribute("height",QString("%1").arg(lineLength.zLength));
                }
                writer.writeEndElement();
                writer.writeEndElement();

                //linkEleID
                writer.writeStartElement("linkEleID");
                writer.writeAttribute("eleID",QString("%1").arg(eleID));
                writer.writeStartElement("PortID");
                writer.writeAttribute("linkIndex","0");

                if(k==0&&m==0)
                {
                    writer.writeAttribute("linkPortIndex",QString("%1").arg(line.leftIndex.toInt()-1));
                    writer.writeAttribute("linkId",QString("%1").arg(leftEquation.id));
                }
                else {
                    writer.writeAttribute("linkPortIndex","0");
                    writer.writeAttribute("linkId",QString("%1").arg(eleID-1));
                }

                QString portDataType;
                for(int n=0;n<m_operator.variables.size();n++)
                {
                    if(m_operator.variables.at(n).name==leftEquation.lefts.at(line.leftIndex.toInt()-1))
                        portDataType=m_operator.variables.at(n).dataType;
                }

                //去掉portDataType中的包路径
                if(portDataType.contains("::"))
                {
                    int lastIndex = portDataType.lastIndexOf("::");
                    portDataType=(lastIndex == -1) ? portDataType : portDataType.mid(lastIndex + 2);
                }

                writer.writeAttribute("portDataType",portDataType);
                writer.writeEndElement();
                writer.writeEndElement();

                //outports
                writer.writeStartElement("outports");
                writer.writeAttribute("EleID",QString("%1").arg(eleID));
                writer.writeStartElement("outportID");
                writer.writeAttribute("outIndex","0");
                writer.writeAttribute("localVarName",leftEquation.lefts.at(line.leftIndex.toInt()-1));
                writer.writeEndElement();
                writer.writeEndElement();

                writer.writeEndElement();

                eleID++;

            }



        }

        if(rightEquation.rightList.at(line.rightIndex.toInt()-1).type=="in")
        {
            //最后一个HLINE
            writer.writeStartElement("EquationGE");
            writer.writeAttribute("EleID",QString("%1").arg(eleID));//EleID
            writer.writeAttribute("presentable",QUuid::createUuid().toString(QUuid::WithoutBraces));//oid

            QString eleType="ELETYPE_LINE";

            writer.writeAttribute("EleType",eleType);
            writer.writeAttribute("OpeName","");
            writer.writeAttribute("Text","");
            writer.writeAttribute("Instance","");
            writer.writeAttribute("UsedIdName","");
            writer.writeAttribute("RefName","");

            //rcMode
            QString rcMode;
            if((x+5)<=line.endX)
                rcMode="HLINE";
            else {
                rcMode="HLINE_REV";
            }

            writer.writeAttribute("rcMode",rcMode);
            writer.writeAttribute("Pattern","0");
            writer.writeAttribute("styleName","");
            writer.writeAttribute("Angle","0");
            writer.writeAttribute("FDOid","");
            writer.writeAttribute("ContainPageName","False");

            //comment
            writer.writeStartElement("comment");
            writer.writeStartElement("Comment");
            writer.writeAttribute("valueStr","");
            writer.writeEndElement();
            writer.writeEndElement();

            //portNum
            writer.writeStartElement("portNum");
            writer.writeStartElement("Number");
            writer.writeAttribute("IfNum","0");
            writer.writeAttribute("InNum","1");
            writer.writeAttribute("ParaNum","0");
            writer.writeAttribute("OutNum","1");
            writer.writeEndElement();
            writer.writeEndElement();

            //position
            writer.writeStartElement("position");
            writer.writeStartElement("Point");
            writer.writeAttribute("x",QString("%1").arg(x));
            writer.writeAttribute("y",QString("%1").arg(y));

            writer.writeEndElement();
            writer.writeEndElement();

            //size
            int width=line.endX-x;

            writer.writeStartElement("size");
            writer.writeStartElement("Size");
            writer.writeAttribute("width",QString("%1").arg(width));
            writer.writeAttribute("height",QString("%1").arg(10));

            writer.writeEndElement();
            writer.writeEndElement();

            //linkEleID
            writer.writeStartElement("linkEleID");
            writer.writeAttribute("eleID",QString("%1").arg(eleID));
            writer.writeStartElement("PortID");
            writer.writeAttribute("linkIndex","0");
            writer.writeAttribute("linkPortIndex","0");
            writer.writeAttribute("linkId",QString("%1").arg(eleID-1));
            QString portDataType;
            for(int n=0;n<m_operator.variables.size();n++)
            {
                if(m_operator.variables.at(n).name==leftEquation.lefts.at(line.leftIndex.toInt()-1))
                    portDataType=m_operator.variables.at(n).dataType;
            }

            //去掉portDataType中的包路径
            if(portDataType.contains("::"))
            {
                int lastIndex = portDataType.lastIndexOf("::");
                portDataType=(lastIndex == -1) ? portDataType : portDataType.mid(lastIndex + 2);
            }

            writer.writeAttribute("portDataType",portDataType);
            writer.writeEndElement();
            writer.writeEndElement();

            //outports
            writer.writeStartElement("outports");
            writer.writeAttribute("EleID",QString("%1").arg(eleID));
            writer.writeStartElement("outportID");
            writer.writeAttribute("outIndex","0");
            writer.writeAttribute("localVarName",leftEquation.lefts.at(line.leftIndex.toInt()-1));
            writer.writeEndElement();
            writer.writeEndElement();

            writer.writeEndElement();

            //        EleID++;
        }

        if(eleID>=eleIDindex)
        {
            eleIDindex=eleID+1;
        }

    }
}

void OperatorImporter::saveVariable(QXmlStreamWriter &writer,const Variable &data)
{
    writer.writeStartElement("Variable");
    writer.writeAttribute("name",data.name);

    writer.writeStartElement("type");

    //普通变量
    if(data.isStruct==false&&data.isArray==false)
    {
        writer.writeStartElement("NamedType");
        writer.writeStartElement("type");
        writer.writeStartElement("TypeRef");
        writer.writeAttribute("name",data.dataType);

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
    }

    //结构体变量
    if(data.isStruct==true)
    {
        writer.writeStartElement("Struct");
        writer.writeStartElement("fields");

        for(int i=0;i<data.fieldList.size();i++)
        {
            writer.writeStartElement("Field");
            writer.writeAttribute("name",data.fieldList.at(i).name);
            writer.writeStartElement("type");
            writer.writeStartElement("NamedType");
            writer.writeStartElement("type");
            writer.writeStartElement("TypeRef");
            writer.writeAttribute("name",data.fieldList.at(i).type);

            writer.writeEndElement();
            writer.writeEndElement();
            writer.writeEndElement();
            writer.writeEndElement();

            writer.writeStartElement("oid");
            writer.writeAttribute("value",data.fieldList.at(i).oid);
            writer.writeEndElement();
            writer.writeEndElement();
        }

        writer.writeEndElement();
        writer.writeEndElement();
    }

    //数组变量
    if(data.isArray==true)
    {
        writer.writeStartElement("Table");
        writer.writeStartElement("type");
        writer.writeStartElement("NamedType");
        writer.writeStartElement("type");
        writer.writeStartElement("TypeRef");
        writer.writeAttribute("name",data.array.type);

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();

        writer.writeStartElement("size");

        //数组大小为立即数时
        if(data.array.size.value.contains(QRegExp("^\\d+$")))
        {
            writer.writeStartElement("ConstValue");
            writer.writeAttribute("value",data.array.size.value);
            writer.writeEndElement();
        }
        else
        {
            writer.writeStartElement("IdExpression");
            writer.writeStartElement("path");
            writer.writeStartElement("ConstVarRef");
            writer.writeAttribute("name",data.array.size.value);

            writer.writeEndElement();
            writer.writeEndElement();
            writer.writeEndElement();
        }

        writer.writeEndElement();


        writer.writeEndElement();
    }

    writer.writeEndElement();

    writer.writeStartElement("oid");
    writer.writeAttribute("value",data.id);
    writer.writeEndElement();

    if(!data.comment.isEmpty())
    {
        writer.writeStartElement("pragmas");
        writer.writeStartElement("comment");
        writer.writeAttribute("value",data.comment);

        writer.writeEndElement();
        writer.writeEndElement();
    }

    writer.writeEndElement();
}

void OperatorImporter::saveEquation(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("Equation");
    writer.writeAttribute("oid",data.pageId);

    //lefts
    if(!data.lefts.isEmpty())
    {
        writer.writeStartElement("lefts");
        for (int i=0;i<data.lefts.size();i++)
        {
            writer.writeStartElement("VariableRef");
            writer.writeAttribute("name",data.lefts.at(i));
            writer.writeEndElement();

        }
        writer.writeEndElement();
    }

    //right
    writer.writeStartElement("right");

    //输入变量、输出变量、本地变量、常量、立即数、结束符
    if(data.type=="inputVar"||data.type=="outputVar"||data.type=="localInputVar"||data.type=="localOutputVar"||data.type=="constant"||data.type=="immediate"||data.type=="terminator")
    {

        if(data.type!="immediate")
        {
            saveIdExpression(writer,data.rightVarRef);

        }
        else {
            writer.writeStartElement("ConstValue");
            writer.writeAttribute("value",data.rightVarRef);
            writer.writeEndElement();
        }

    }

    //操作符
    if(data.type=="operator")
    {
        saveOperator(writer,data);
    }

    writer.writeEndElement();//right

    //oid
    writer.writeStartElement("oid");
    writer.writeAttribute("value",data.redaceId);
    writer.writeEndElement();

    //comment
    if(!data.comment.isEmpty())
    {
        writer.writeStartElement("pragmas");
        writer.writeStartElement("comment");
        writer.writeAttribute("value",data.comment);

        writer.writeEndElement();
        writer.writeEndElement();
    }

    writer.writeEndElement();
}

void OperatorImporter::saveOperator(QXmlStreamWriter &writer,const Equation &data)
{
    //一元操作符
    if(data.operatorType=="UnaryOp")
        saveUnaryOp(writer,data);

    //二元操作符
    if(data.operatorType=="BinaryOp")
        saveBinaryOp(writer,data);

    //多元操作符
    if(data.operatorType=="NAryOp")
        saveNAryOp(writer,data);

    //Previous
    if(data.operatorType=="PreOp")
        savePreOp(writer,data);

    //Init
    if(data.operatorType=="InitOp")
        saveInitOp(writer,data);

    //Followed By
    if(data.operatorType=="FbyOp")
        saveFbyOp(writer,data);

    //Projection
    if(data.operatorType=="PrjOp")
        savePrjOp(writer,data);

    //Slice
    if(data.operatorType=="SliceOp")
        saveSliceOp(writer,data);

    //Dynamic Projection
    if(data.operatorType=="PrjDynOp")
        savePrjDynOp(writer,data);

    //DataStructre
    if(data.operatorType=="DataStructOp")
        saveDataStructOp(writer,data);

    //ScalarToVector
    if(data.operatorType=="ScalarToVectorOp")
        saveScalarToVectorOp(writer,data);

    //DataArray
    if(data.operatorType=="DataArrayOp")
        saveDataArrayOp(writer,data);

    //ChgIthOp
    if(data.operatorType=="ChgIthOp")
        saveChgIthOp(writer,data);

    //IfThenElse
    if(data.operatorType=="IfThenElseOp")
        saveIfThenElseOp(writer,data);

    //Case
    if(data.operatorType=="CaseOp")
        saveCaseOp(writer,data);

    //Make
    if(data.operatorType=="MakeOp")
        saveMakeOp(writer,data);

    //Flatten
    if(data.operatorType=="FlattenOp")
        saveFlattenOp(writer,data);

    //Iterator
    if(data.operatorType=="IteratorOp")
        saveIteratorOp(writer,data);

    //PartialIterator
    if(data.operatorType=="PartialIteratorOp")
        savePartialIteratorOp(writer,data);

    //OpCall
    if(data.operatorType=="OpCall")
        saveOpCall(writer,data);
}

void OperatorImporter::saveUnaryOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("UnaryOp");

    if(data.operatorName=="Unary Minus")
        writer.writeAttribute("operator","-");

    if(data.operatorName=="Not")
        writer.writeAttribute("operator","not");

    if(data.operatorName=="Convert To Integer")
        writer.writeAttribute("operator","int");

    if(data.operatorName=="Convert To Real")
        writer.writeAttribute("operator","real");

    writer.writeStartElement("operand");

    saveIdExpression(writer,data.unaryOp.constVarRef);

    writer.writeEndElement();
    writer.writeEndElement();
}

void OperatorImporter::saveBinaryOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("BinaryOp");

    if(data.operatorName=="Minus")
        writer.writeAttribute("operator","-");

    if(data.operatorName=="Polymorphic Division")
        writer.writeAttribute("operator","/");

    if(data.operatorName=="Integer Division")
        writer.writeAttribute("operator","div");

    if(data.operatorName=="Modulo")
        writer.writeAttribute("operator","mod");

    if(data.operatorName=="Strictly Less Than")
        writer.writeAttribute("operator","<");

    if(data.operatorName=="Less Than Or Equal")
        writer.writeAttribute("operator","<=");

    if(data.operatorName=="Strictly Greater Than")
        writer.writeAttribute("operator",">");

    if(data.operatorName=="Greater Than Or Equal")
        writer.writeAttribute("operator",">=");

    if(data.operatorName=="Different")
        writer.writeAttribute("operator","<>");

    if(data.operatorName=="Equal")
        writer.writeAttribute("operator","=");

    writer.writeStartElement("operands");

    saveIdExpression(writer,data.binaryOp.constVarRefs.at(0));
    saveIdExpression(writer,data.binaryOp.constVarRefs.at(1));

    writer.writeEndElement();
    writer.writeEndElement();
}

void OperatorImporter::saveNAryOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("NAryOp");

    if(data.operatorName=="Plus")
        writer.writeAttribute("operator","+");

    if(data.operatorName=="Multiplication")
        writer.writeAttribute("operator","*");

    if(data.operatorName=="And")
        writer.writeAttribute("operator","and");

    if(data.operatorName=="Or")
        writer.writeAttribute("operator","or");

    if(data.operatorName=="Exclusive Or")
        writer.writeAttribute("operator","xor");

    writer.writeStartElement("operands");

    for (int i=0;i<data.nAryOp.constVarRefs.size();i++)
    {
        saveIdExpression(writer,data.nAryOp.constVarRefs.at(i));

    }

    writer.writeEndElement();
    writer.writeEndElement();
}

void OperatorImporter::savePreOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("PreOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    writer.writeStartElement("flow");

    writer.writeStartElement("ListExpression");

    writer.writeStartElement("items");

    for (int i=0;i<data.preOp.flows.size();i++)
    {
        saveIdExpression(writer,data.preOp.flows.at(i));

    }

    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
}

void OperatorImporter::saveInitOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("InitOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //value
    writer.writeStartElement("value");
    writer.writeStartElement("ListExpression");
    writer.writeStartElement("items");

    for (int i=0;i<data.initOp.parameters.size();i++)
    {
        saveParameter(writer,data.initOp.parameters.at(i));
    }

    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();

    //flow
    writer.writeStartElement("flow");

    writer.writeStartElement("ListExpression");

    writer.writeStartElement("items");

    for (int i=0;i<data.initOp.flows.size();i++)
    {
        saveIdExpression(writer,data.initOp.flows.at(i));
    }

    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
}

void OperatorImporter::saveFbyOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("FbyOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //flows
    writer.writeStartElement("flows");
    for(int i=0;i<data.fbyOp.flows.size();i++)
    {
        saveIdExpression(writer,data.fbyOp.flows.at(i));
    }
    writer.writeEndElement();

    //delay
    writer.writeStartElement("delay");
    saveParameter(writer,data.fbyOp.delay);
    writer.writeEndElement();

    //values
    writer.writeStartElement("values");
    for(int i=0;i<data.fbyOp.parameters.size();i++)
    {
        saveParameter(writer,data.fbyOp.parameters.at(i));
    }
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::savePrjOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("PrjOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //flow
    writer.writeStartElement("flow");
    saveIdExpression(writer,data.prjOp.flow);
    writer.writeEndElement();

    //with
    writer.writeStartElement("with");
    for(int i=0;i<data.prjOp.parameters.size();i++)
    {
        saveParameter(writer,data.prjOp.parameters.at(i));
    }
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::saveSliceOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("SliceOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //array
    writer.writeStartElement("array");
    saveIdExpression(writer,data.sliceOp.array);
    writer.writeEndElement();

    //fromIndex
    writer.writeStartElement("fromIndex");
    saveParameter(writer,data.sliceOp.fromIndex);
    writer.writeEndElement();

    //toIndex
    writer.writeStartElement("toIndex");
    saveParameter(writer,data.sliceOp.toIndex);
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::savePrjDynOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("PrjDynOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //array
    writer.writeStartElement("array");
    saveIdExpression(writer,data.prjDynOp.array);
    writer.writeEndElement();

    //indexes
    writer.writeStartElement("indexes");
    for(int i=0;i<data.prjDynOp.indexes.size();i++)
    {
        saveParameter(writer,data.prjDynOp.indexes.at(i));
    }
    writer.writeEndElement();

    //default
    writer.writeStartElement("default");
    saveParameter(writer,data.prjDynOp.defaultpara);
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::saveDataStructOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("DataStructOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //data
    writer.writeStartElement("data");

    for(int i=0;i<data.dataStructOp.labels.size();i++)
    {
        writer.writeStartElement("LabelledExpression");
        writer.writeAttribute("label",data.dataStructOp.labels.at(i).labelName);
        writer.writeStartElement("flow");
        saveIdExpression(writer,data.dataStructOp.labels.at(i).value);

        writer.writeEndElement();
        writer.writeEndElement();
    }

    writer.writeEndElement();
    writer.writeEndElement();
}

void OperatorImporter::saveScalarToVectorOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("ScalarToVectorOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //flow
    writer.writeStartElement("flow");
    writer.writeStartElement("ListExpression");
    writer.writeStartElement("items");
    for(int i=0;i<data.scalarToVectorOp.flows.size();i++)
    {
        saveIdExpression(writer,data.scalarToVectorOp.flows.at(i));
    }
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();

    //size
    writer.writeStartElement("size");
    saveParameter(writer,data.scalarToVectorOp.size);
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::saveDataArrayOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("DataArrayOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //data
    writer.writeStartElement("data");
    for(int i=0;i<data.dataArrayOp.datas.size();i++)
    {
        saveIdExpression(writer,data.dataArrayOp.datas.at(i));
    }
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::saveChgIthOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("ChgIthOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //flow
    writer.writeStartElement("flow");
    saveIdExpression(writer,data.chgIthOp.flow);
    writer.writeEndElement();

    //with
    writer.writeStartElement("with");
    for(int i=0;i<data.chgIthOp.parameters.size();i++)
    {
        saveParameter(writer,data.chgIthOp.parameters.at(i));
    }
    writer.writeEndElement();

    //value
    writer.writeStartElement("value");
    saveIdExpression(writer,data.chgIthOp.value);
    writer.writeEndElement();

    writer.writeEndElement();

}

void OperatorImporter::saveIfThenElseOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("IfThenElseOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //if
    writer.writeStartElement("if");
    saveIdExpression(writer,data.ifThenElseOp.ifValue);
    writer.writeEndElement();

    //then
    writer.writeStartElement("then");
    writer.writeStartElement("ListExpression");
    writer.writeStartElement("items");
    for(int i=0;i<data.ifThenElseOp.thens.size();i++)
    {
        saveIdExpression(writer,data.ifThenElseOp.thens.at(i));
    }
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();

    //else
    writer.writeStartElement("else");
    writer.writeStartElement("ListExpression");
    writer.writeStartElement("items");
    for(int i=0;i<data.ifThenElseOp.elses.size();i++)
    {
        saveIdExpression(writer,data.ifThenElseOp.elses.at(i));
    }
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::saveCaseOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("CaseOp");

    writer.writeAttribute("name",QString("%1").arg(data.id));

    //switch
    writer.writeStartElement("switch");
    saveIdExpression(writer,data.caseOp.switchValue);
    writer.writeEndElement();

    //cases
    writer.writeStartElement("cases");

    for(int i=0;i<data.caseOp.cases.size();i++)
    {
        writer.writeStartElement("Case");
        writer.writeAttribute("pattern",data.caseOp.cases.at(i).labelName);
        writer.writeStartElement("flow");
        saveIdExpression(writer,data.caseOp.cases.at(i).value);
        writer.writeEndElement();
        writer.writeEndElement();
    }

    //default
    writer.writeStartElement("Case");
    writer.writeStartElement("flow");
    saveIdExpression(writer,data.caseOp.defaultValue);
    writer.writeEndElement();
    writer.writeEndElement();

    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::saveMakeOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("CallExpression");

    //operator
    writer.writeStartElement("operator");
    writer.writeStartElement("MakeOp");
    writer.writeAttribute("name",QString("%1").arg(data.id));
    writer.writeStartElement("type");
    writer.writeStartElement("TypeRef");
    writer.writeAttribute("name",data.makeOp.typeRef);

    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();


    //callParameters
    if(!data.makeOp.calls.isEmpty())
    {
        writer.writeStartElement("callParameters");
        for(int i=0;i<data.makeOp.calls.size();i++)
        {
            saveIdExpression(writer,data.makeOp.calls.at(i));
        }
        writer.writeEndElement();
    }

    writer.writeEndElement();
}

void OperatorImporter::saveFlattenOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("CallExpression");

    //operator
    writer.writeStartElement("operator");
    writer.writeStartElement("FlattenOp");
    writer.writeAttribute("name",QString("%1").arg(data.id));
    writer.writeStartElement("type");
    writer.writeStartElement("TypeRef");
    if(data.flattenOp.typeRef.isEmpty())
        writer.writeAttribute("name","_null");
    else {
        writer.writeAttribute("name",data.flattenOp.typeRef);
    }

    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();

    //callParameters
    writer.writeStartElement("callParameters");
    saveIdExpression(writer,data.flattenOp.call);
    writer.writeEndElement();

    writer.writeEndElement();
}

void OperatorImporter::saveIteratorOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("CallExpression");

    //operator
    writer.writeStartElement("operator");
    writer.writeStartElement("IteratorOp");
    writer.writeAttribute("iterator",data.iteratorOp.iteratorType);

    writer.writeStartElement("operator");
    if(data.iteratorOp.isMakeOp==false&&data.iteratorOp.isFlattenOp==false)
    {
        writer.writeStartElement("OpCall");
        writer.writeAttribute("name",QString("%1").arg(data.id));
        writer.writeStartElement("operator");
        writer.writeStartElement("OperatorRef");
        writer.writeAttribute("name",data.iteratorOp.operatorRef);

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
    }

    if(data.iteratorOp.isMakeOp==true)
    {
        writer.writeStartElement("MakeOp");
        writer.writeAttribute("name",QString("%1").arg(data.id));
        writer.writeStartElement("type");
        writer.writeStartElement("TypeRef");
        writer.writeAttribute("name",data.iteratorOp.makeRef);

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
    }

    if(data.iteratorOp.isFlattenOp==true)
    {
        writer.writeStartElement("FlattenOp");
        writer.writeAttribute("name",QString("%1").arg(data.id));
        writer.writeStartElement("type");
        writer.writeStartElement("TypeRef");

        if(data.iteratorOp.flattenRef.isEmpty())
            writer.writeAttribute("name","_null");
        else {
            writer.writeAttribute("name",data.iteratorOp.flattenRef);
        }

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
    }

    writer.writeEndElement();

    //size
    writer.writeStartElement("size");
    writer.writeStartElement("ConstValue");
    writer.writeAttribute("value",data.iteratorOp.size.value);

    writer.writeEndElement();
    writer.writeEndElement();

    writer.writeEndElement();
    writer.writeEndElement();

    //callParameters
    if(!data.iteratorOp.calls.isEmpty())
    {
        writer.writeStartElement("callParameters");

        for(int i=0;i<data.iteratorOp.calls.size();i++)
        {
            saveIdExpression(writer,data.iteratorOp.calls.at(i));
        }
        writer.writeEndElement();
    }

    writer.writeEndElement();
}

void OperatorImporter::savePartialIteratorOp(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("CallExpression");

    //operator
    writer.writeStartElement("operator");
    writer.writeStartElement("PartialIteratorOp");
    writer.writeAttribute("iterator",data.partialIteratorOp.partialIteratorType);

    writer.writeStartElement("operator");
    if(data.partialIteratorOp.isMakeOp==false&&data.partialIteratorOp.isFlattenOp==false)
    {
        writer.writeStartElement("OpCall");
        writer.writeAttribute("name",QString("%1").arg(data.id));
        writer.writeStartElement("operator");
        writer.writeStartElement("OperatorRef");
        writer.writeAttribute("name",data.partialIteratorOp.operatorRef);

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
    }

    if(data.partialIteratorOp.isMakeOp==true)
    {
        writer.writeStartElement("MakeOp");
        writer.writeAttribute("name",QString("%1").arg(data.id));
        writer.writeStartElement("type");
        writer.writeStartElement("TypeRef");
        writer.writeAttribute("name",data.partialIteratorOp.makeRef);

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
    }

    if(data.partialIteratorOp.isFlattenOp==true)
    {
        writer.writeStartElement("FlattenOp");
        writer.writeAttribute("name",QString("%1").arg(data.id));
        writer.writeStartElement("type");
        writer.writeStartElement("TypeRef");

        if(data.partialIteratorOp.flattenRef.isEmpty())
            writer.writeAttribute("name","_null");
        else {
            writer.writeAttribute("name",data.partialIteratorOp.flattenRef);
        }

        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
    }

    writer.writeEndElement();

    //size
    writer.writeStartElement("size");
    writer.writeStartElement("ConstValue");
    writer.writeAttribute("value",data.partialIteratorOp.size.value);

    writer.writeEndElement();
    writer.writeEndElement();

    //if
    writer.writeStartElement("if");
    saveIdExpression(writer,data.partialIteratorOp.ifValue);
    writer.writeEndElement();

    //default
    if(data.partialIteratorOp.partialIteratorType=="mapw"||data.partialIteratorOp.partialIteratorType=="mapwi")
    {
        writer.writeStartElement("default");
        writer.writeStartElement("ListExpression");

        writer.writeEndElement();
        writer.writeEndElement();
    }

    writer.writeEndElement();
    writer.writeEndElement();

    //callParameters
    if(!data.partialIteratorOp.calls.isEmpty())
    {
        writer.writeStartElement("callParameters");

        for(int i=0;i<data.partialIteratorOp.calls.size();i++)
        {
            saveIdExpression(writer,data.partialIteratorOp.calls.at(i));
        }
        writer.writeEndElement();
    }

    writer.writeEndElement();

}

void OperatorImporter::saveOpCall(QXmlStreamWriter &writer,const Equation &data)
{
    writer.writeStartElement("CallExpression");

    //operator
    writer.writeStartElement("operator");
    writer.writeStartElement("OpCall");
    writer.writeAttribute("name",QString("%1").arg(data.id));
    writer.writeStartElement("operator");
    writer.writeStartElement("OperatorRef");
    writer.writeAttribute("name",data.opCall.operatorRef);

    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();

    //callParameters
    if(!data.opCall.calls.isEmpty())
    {
        writer.writeStartElement("callParameters");
        for(int i=0;i<data.opCall.calls.size();i++)
        {
            saveIdExpression(writer,data.opCall.calls.at(i));
        }
        writer.writeEndElement();
    }

    writer.writeEndElement();
}

void OperatorImporter::saveIdExpression(QXmlStreamWriter &writer,const QString &data)
{
    writer.writeStartElement("IdExpression");
    writer.writeStartElement("path");
    writer.writeStartElement("ConstVarRef");
    if(data.isEmpty())
        writer.writeAttribute("name","_null");
    else {
        writer.writeAttribute("name",data);
    }

    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
}

void OperatorImporter::saveParameter(QXmlStreamWriter &writer,const parameter &data)
{
    if(data.isImmediate==false)
        saveIdExpression(writer,data.value);
    else {
        writer.writeStartElement("ConstValue");
        writer.writeAttribute("value",data.value);
        writer.writeEndElement();
    }
}

void OperatorImporter::parseVariables(const QDomElement &element)
{

    QDomNodeList items=element.childNodes();
    for (int i = 0;i < items.count();i++)
    {
        Variable data;

        if(element.tagName()=="inputs")
            data.type="input";

        if(element.tagName()=="outputs")
            data.type="output";

        if(element.tagName()=="locals")
            data.type="local";

        //报告signal
        if(element.tagName()=="signals")
        {
            m_operator.logList.append("存在REDACE不支持的signal;");
            continue;
        }

        QDomNode item = items.at(i);
        data.node=items.at(i);

        QDomElement ele = item.toElement();

        QDomNode typeNode;
        QDomNode lastNode;
        QDomNode defaultNode;
        QDomNode idNode;
        QDomNode pragmasNode;
        QDomNode commentNode;

        QDomNodeList nodeList=ele.childNodes();

        for(int i=0;i<nodeList.size();i++)
        {
            if(nodeList.at(i).toElement().tagName()=="type")
                typeNode=ele.childNodes().at(i);

            if(nodeList.at(i).toElement().tagName()=="default")
                defaultNode=ele.childNodes().at(i);

            if(nodeList.at(i).toElement().tagName()=="last")
                lastNode=ele.childNodes().at(i);

            if(nodeList.at(i).toElement().tagName()=="pragmas")
                pragmasNode=ele.childNodes().at(i);
        }

        QDomElement typeEle=typeNode.firstChild().toElement();

        idNode=pragmasNode.firstChild();

        if(!idNode.firstChild().isNull())
            commentNode=idNode.firstChild();

        data.id=getOid(idNode);


        data.comment=getComment(commentNode);

        data.name=ele.attribute("name");

        QString tagName=typeEle.tagName();

        //解析普通类型变量
        if(tagName=="NamedType")
        {
            parseNomalVariable(data,typeEle);
        }

        //解析结构体类型变量
        if(tagName=="Struct")
        {
            data.isStruct=true;
            parseStructVariable(data,typeEle);
        }

        //解析数组类型变量
        if(tagName=="Table")
        {
            data.isArray=true;
            parseArrayVariable(data,typeEle);
        }

        //报告变量和操作符重名
        if(data.name==m_operator.operatorName)
        {
            m_operator.logList.append("变量"+data.name+"与操作符重名");
        }

        //default
        if(!defaultNode.isNull())
        {
            //default为表达式时
            if(defaultNode.firstChild().isComment())
            {
                data.defaultNode=defaultNode.childNodes().at(1);
                data.defaultValue=defaultNode.firstChild().nodeValue();
            }
            else
            {
                data.defaultNode=defaultNode.firstChild().cloneNode(true);
                if(defaultNode.firstChild().toElement().tagName()=="IdExpression")
                {
                    data.defaultValue=defaultNode.firstChild().firstChild().firstChild().toElement().attribute("name");
                }

                if(defaultNode.firstChild().toElement().tagName()=="ConstValue")
                {
                    data.defaultValue=defaultNode.firstChild().toElement().attribute("value");
                }
            }

            m_operator.logList.append("变量"+data.name+"有默认值,默认值为"+data.defaultValue);
        }

        //Last
        if(!lastNode.isNull())
        {
            //last值为表达式时
            if(lastNode.firstChild().isComment())
            {
                data.lastNode=lastNode.childNodes().at(1);
                data.lastValue=lastNode.firstChild().nodeValue();

            }
            else {
                data.lastNode=lastNode.firstChild().cloneNode(true);
                if(lastNode.firstChild().toElement().tagName()=="IdExpression")
                {
                    data.lastValue=lastNode.firstChild().firstChild().firstChild().toElement().attribute("name");
                }

                if(lastNode.firstChild().toElement().tagName()=="ConstValue")
                {
                    data.lastValue=lastNode.firstChild().toElement().attribute("value");
                }
            }

        }

        if(data.type=="local"&&data.name.startsWith("_L")&&data.name.mid(2).contains(QRegExp("^\\d+$")))//本地变量名以_L开头，后续为纯数字认为为端口
            data.isLine=true;

        m_operator.variables.append(data);

    }

}

void OperatorImporter::parseNomalVariable(Variable &data,const QDomElement &element)
{
    QDomElement typeRefElement=element.firstChild().firstChild().toElement();

    data.dataType=typeRefElement.attribute("name");
    //报告泛型
    if(data.dataType=="'T")
    {
        data.hasT=true;
        m_operator.hasT=true;
        m_operator.logList.append("变量"+data.name+"为'T");
    }
}

void OperatorImporter::parseStructVariable(Variable &data,const QDomElement &element)
{
    QDomNodeList fieldList=element.firstChild().childNodes();

    data.dataType="{";

    for(int i=0;i<fieldList.size();i++)
    {
        Field field;

        QDomNode fieldNode=fieldList.at(i);
        QDomNode typeNode=fieldNode.firstChild();
        QDomNode pragmasNode=typeNode.nextSibling();
        QDomNode typeRefNode=typeNode.firstChild().firstChild().firstChild();

        field.name=fieldNode.toElement().attribute("name");
        field.type=typeRefNode.toElement().attribute("name");
        field.oid=pragmasNode.firstChild().toElement().attribute("oid");
        data.dataType=data.dataType+field.name+":"+field.type;

        if(i!=fieldList.size()-1)
        {
            data.dataType=data.dataType+",";
        }

        //报告结构体元素中的泛型
        if(field.type=="'T")
        {
            data.hasT=true;
            m_operator.hasT=true;
            m_operator.logList.append("结构体变量"+data.name+"的元素"+field.name+"为'T");
        }

        data.fieldList.append(field);
    }

    data.dataType=data.dataType+"}";

}

void OperatorImporter::parseArrayVariable(Variable &data,const QDomElement &element)
{
    QDomNode typeNode=element.firstChild();
    QDomNode indexNode=typeNode.firstChild();

    if(indexNode.toElement().tagName()=="NamedType")
    {
        QDomNode typeRefNode=indexNode.firstChild().firstChild();
        data.array.type=typeRefNode.toElement().attribute("name");

        //报告泛型数组
        if(data.array.type=="'T")
        {
            data.hasT=true;
            m_operator.hasT=true;
            m_operator.logList.append("数组变量"+data.name+"的数据类型为'T");
        }
    }

    //报告结构体数组泛型
    if(indexNode.toElement().tagName()=="Struct")
    {
        QDomNode fieldsNode=indexNode.firstChild();
        QDomNodeList nodeList=fieldsNode.childNodes();

        for(int i=0;i<nodeList.size();i++)
        {
            QDomNode node=nodeList.at(i);
            QString fieldName=node.toElement().attribute("name");
            QDomNode typeRef=node.firstChild().firstChild().firstChild().firstChild();

            if(typeRef.toElement().attribute("name")=="'T")
            {
                data.hasT=true;
                m_operator.hasT=true;
                m_operator.logList.append("结构体数组变量"+data.name+"的元素"+fieldName+"为'T");
            }
        }
    }

//    QDomNode typeRefNode=typeNode.firstChild().firstChild().firstChild();
    QDomNode sizeNode=typeNode.nextSibling();

//    data.array.type=typeRefNode.toElement().attribute("name");

    if(sizeNode.childNodes().size()==2)
    {
        data.array.size=parseParameter(sizeNode.childNodes().at(1).toElement());
    }
    else {
        data.array.size=parseParameter(sizeNode.firstChild().toElement());
    }

    //判断数组大小是否为参数
    if(data.array.size.value==m_operator.parameter)
        data.hasPara=true;

    data.dataType=data.array.type+"^"+data.array.size.value;

}

void OperatorImporter::parseDatas(const QDomElement &element)
{
    int fbyName=10000;//last转为Fby时，FbyOp的name

    QDomNodeList items=element.childNodes();

    //获取所有页面的EquationGE
    QDomNode operatorNode=element.parentNode();

    QDomNodeList nodeList=operatorNode.childNodes();

    QList<QDomNode> equationGEList;

    for(int i=0;i<nodeList.size();i++)
    {
        if(nodeList.at(i).toElement().tagName()=="pragmas")
        {
            QDomNode pragmasNode=nodeList.at(i);

            QDomNodeList list=pragmasNode.firstChild().childNodes();

            for(int i=0;i<list.size();i++)
            {
                if(list.at(i).toElement().tagName()=="diagrams")
                {
                    QDomNode diagramsNode=list.at(i);

                    QDomNodeList diagList=diagramsNode.childNodes();

                    for(int i=0;i<diagList.size();i++)
                    {
                        QDomNodeList nodeList=diagList.at(i).firstChild().childNodes();

                        for(int i=0;i<nodeList.size();i++)
                        {
                            if(nodeList.at(i).toElement().tagName()=="EquationGE")
                                equationGEList.append(nodeList.at(i));
                        }
                    }
                }
            }

        }
    }

    for (int i = 0;i < items.count();i++)
    {
        if(!element.hasChildNodes())
            return;

        QDomNode item = items.at(i);
        QDomElement ele = item.toElement();

        //报告状态机图
        if(ele.tagName()=="StateMachine")
        {
            m_operator.logList.append("存在状态机图无法导入;");
        }

        //报告ifblock
        if(ele.tagName()=="IfBlock")
        {
            m_operator.logList.append("存在IfBlock无法导入;");
        }

        if(ele.tagName()=="Equation")
        {

            QDomElement leftsEle;
            QDomElement rightEle;
            QDomElement pragmasEle;

            QDomNodeList equationChilds=ele.childNodes();
            for(int i=0;i<equationChilds.size();i++)
            {
                QString tagName=equationChilds.at(i).toElement().tagName();

                if(tagName=="lefts")
                    leftsEle=equationChilds.at(i).toElement();

                if(tagName=="right")
                    rightEle=equationChilds.at(i).toElement();

                if(tagName=="pragmas")
                    pragmasEle=equationChilds.at(i).toElement();
            }

            QDomNode idNode=pragmasEle.firstChild();
            QDomNode commentNode;

            if(idNode.hasChildNodes()&&idNode.firstChild().toElement().tagName()=="comment")
                commentNode=idNode.firstChild();

            QDomNodeList variableRefs=leftsEle.childNodes();

            Equation data;

            data.node=ele;

            data.oid=getOid(idNode);
            data.comment=getComment(commentNode);

            //判断图元类型
            //变量、常量、结束符
            if(rightEle.firstChild().toElement().tagName()=="IdExpression"||rightEle.firstChild().toElement().tagName()=="Last")
            {
                QDomElement constVarRef=rightEle.firstChild().firstChild().firstChild().toElement();

                QString variableRefName=variableRefs.at(0).toElement().attribute("name");

                QString constVarRefName;
                if(constVarRef.hasAttribute("name"))
                    constVarRefName=constVarRef.attribute("name");

                for(int i = 0;i < m_operator.variables.size();i++)
                {
                    Variable var=m_operator.variables.at(i);

                    if(rightEle.firstChild().toElement().tagName()=="Last")
                    {
                        if(var.name==constVarRefName)
                        {
                            data.isLastVar=true;
                            data.type="immediate";
                            data.lefts.append(variableRefName);
                            data.text="fby("+constVarRefName+";"+"1;"+var.lastValue+")";
                            //修改last变量的node
                            QDomDocument doc;

                            //FbyOp
                            QDomElement fbyOpElement=doc.createElement("FbyOp");
                            fbyOpElement.setAttribute("name",fbyName);
                            fbyName++;

                            //flows
                            QDomElement flowsElement=doc.createElement("flows");
                            fbyOpElement.appendChild(flowsElement);
                            QDomElement idExpressionElement=doc.createElement("IdExpression");
                            flowsElement.appendChild(idExpressionElement);
                            QDomElement pathElement=doc.createElement("path");
                            idExpressionElement.appendChild(pathElement);
                            QDomNode node=data.node.childNodes().at(1).firstChild().firstChild().firstChild();
                            pathElement.appendChild(node);

                            //delay
                            QDomElement delayElement=doc.createElement("delay");
                            fbyOpElement.appendChild(delayElement);
                            QDomElement constValueElement=doc.createElement("ConstValue");
                            constValueElement.setAttribute("value","1");
                            delayElement.appendChild(constValueElement);

                            //values
                            QDomElement valuesElement=doc.createElement("values");
                            fbyOpElement.appendChild(valuesElement);
                            valuesElement.appendChild(var.lastNode.cloneNode(true));

                            data.node.childNodes().at(1).replaceChild(fbyOpElement,data.node.childNodes().at(1).firstChild());
                        }

                    }
                    else {
                        //输入变量
                        if(var.type=="input"&&var.name==constVarRefName)
                        {
                            data.type="inputVar";
                            data.lefts.append(variableRefName);
                            data.name=var.name;
                            data.rightVarRef=constVarRefName;
                        }

                        //输出变量
                        if(var.type=="output"&&var.name==variableRefs.at(0).toElement().attribute("name"))
                        {
                            data.type="outputVar";
                            data.lefts.append(var.name);
                            data.name=var.name;
                            data.rightVarRef=constVarRefName;
                        }

                        //本地输入变量
                        if(var.type=="local"&&var.isLine==false&&var.name==constVarRefName&&data.type.isEmpty())
                        {
//                            QString str=variableRefs.at(0).toElement().attribute("name");
//                            if(judgeVarType(str)=="local")
//                            {
                                data.type="localInputVar";
                                data.lefts.append(variableRefName);
                                data.name=var.name;
                                data.rightVarRef=constVarRefName;
//                            }

                        }

                        //本地输出变量
                        if(var.type=="local"&&var.isLine==false&&var.name==variableRefs.at(0).toElement().attribute("name")&&data.type.isEmpty())
                        {
//                            if(judgeVarType(constVarRefName)=="local")
//                            {
                                data.type="localOutputVar";
                                data.lefts.append(var.name);
                                data.name=var.name;
                                data.rightVarRef=constVarRefName;
//                            }

                        }


                    }
                }



                //常量
                if(data.type.isEmpty()&&variableRefName!="_")
                {
                    data.type="constant";
                    data.lefts.append(variableRefName);

                    //处理包中的常量
                    if(constVarRefName.contains("::"))
                    {
                        QStringList list=constVarRefName.split("::");
                        constVarRefName=list.at(list.size()-1);
                        constVarRef.setAttribute("name",constVarRefName);
                    }

                    data.name=constVarRefName;
                    data.rightVarRef=constVarRefName;

                    //参数输入
                    if(constVarRefName==m_operator.parameter)
                    {
                        data.isParaHigh=true;
                    }

                }

                //结束符
                if(data.type.isEmpty()&&variableRefName=="_")
                {
                    data.type="terminator";
                    data.lefts.append(variableRefName);
                    //                    data.name=constVarRefName;
                    data.rightVarRef=constVarRefName;
                }


            }
            else
            {
                //立即数
                for(int i=0;i<equationGEList.size();i++)
                {
                    if(data.oid==equationGEList.at(i).toElement().attribute("presentable"))
                    {
                        if(equationGEList.at(i).toElement().hasAttribute("kind")&&equationGEList.at(i).toElement().attribute("kind")=="OBJ_LIT")
                        {
                            data.type="immediate";
                            data.lefts.append(variableRefs.at(0).toElement().attribute("name"));

                            QDomNodeList rightChild=rightEle.childNodes();

                            //                            for(int i=0;i<rightChild.size();i++)
                            //                            {
                            //                                QDomNode node=rightChild.at(i);
                            //                                qDebug()<<"name:"<<node.nodeName()<<",value"<<node.nodeValue();
                            //                            }

                            //有注释
                            if(rightChild.size()==2)
                            {
                                data.text=rightEle.firstChild().nodeValue();

                            }
                            else
                            {
                                if(rightEle.firstChild().toElement().tagName()=="ConstValue")
                                {
                                    data.rightVarRef=rightEle.firstChild().toElement().attribute("value");
                                    data.text=data.rightVarRef;
                                }

                                if(rightEle.firstChild().toElement().tagName()=="TextExpression")
                                {
                                    data.text=rightEle.firstChild().toElement().attribute("text");
                                }

                            }


                        }

                    }

                }


                //操作符
                if(data.type.isEmpty())
                {
                    data.type="operator";//操作符
                    for(int i=0;i<variableRefs.size();i++)
                    {
                        data.lefts.append(variableRefs.at(i).toElement().attribute("name"));
                    }

                    QDomElement operatorEle=rightEle.firstChild().nextSibling().toElement();
                    parseBaseOperator(operatorEle,data);
                }

            }
            //            else if (rightEle.firstChild().toElement().tagName()=="ConstValue")//立即数
            //            {
            //                data.type="immediate";
            //                data.lefts.append(variableRefs.at(0).toElement().attribute("name"));
            //                data.rightVarRef=rightEle.firstChild().toElement().attribute("value");
            //            }
            //            else
            //            {
            //                data.type="operator";//操作符
            //                for(int i=0;i<variableRefs.size();i++)
            //                {
            //                    data.lefts.append(variableRefs.at(i).toElement().attribute("name"));
            //                }

            //                QDomElement operatorEle=rightEle.firstChild().nextSibling().toElement();
            //                parseBaseOperator(file,operatorEle,data);

            //            }

            m_operator.equations.append(data);
        }

    }


}

QString OperatorImporter::getOid(const QDomNode &idNode)
{
    // 获取oid
    QString oid;
    QDomElement idElement = idNode.toElement();
    if(idElement.hasAttribute("oid"))
    {
        oid = idElement.attribute("oid");
    }
    return  oid;
}

QString OperatorImporter::getComment(const QDomNode &commentNode)
{
    // 获取描述信息
    QString comment;
    QDomElement comtElement = commentNode.toElement();

    comment = comtElement.text();

    return comment;
}

void OperatorImporter::parseBaseOperator(const QDomElement &element,Equation &data)
{
    QString tagName=element.tagName();

    //一元操作符
    if(tagName=="UnaryOp")
        parseUnaryOp(element,data);

    //二元操作符
    if(tagName=="BinaryOp")
        parseBinaryOp(element,data);

    //多元操作符
    if(tagName=="NAryOp")
        parseNAryOp(element,data);

    //时序操作符
    //Previous
    if(tagName=="PreOp")
        parsePreOp(element,data);

    //Init
    if(tagName=="InitOp")
        parseInitOp(element,data);

    //Followed By
    if(tagName=="FbyOp")
        parseFbyOp(element,data);

    //Projection
    if(tagName=="PrjOp")
        parsePrjOp(element,data);

    //Slice
    if(tagName=="SliceOp")
        parseSliceOp(element,data);

    //Dynamic Projection
    if(tagName=="PrjDynOp")
        parsePrjDynOp(element,data);

    //DataStructure
    if(tagName=="DataStructOp")
        parseDataStructOp(element,data);

    //ScalarToVector
    if(tagName=="ScalarToVectorOp")
        parseScalarToVectorOp(element,data);

    //DataArray
    if(tagName=="DataArrayOp")
        parseDataArrayOp(element,data);

    //Assign of a Structured Element
    if(tagName=="ChgIthOp")
        parseChgIthOp(element,data);

    //If Then Else
    if(tagName=="IfThenElseOp")
        parseIfThenElseOp(element,data);

    //Case
    if(tagName=="CaseOp")
        parseCaseOp(element,data);

    //ExprOp
    if(tagName=="CallExpression")
    {
        QDomElement operatorEle=element.firstChild().toElement();

        //Make
        if(operatorEle.tagName()=="operator"&&operatorEle.firstChild().toElement().tagName()=="MakeOp")
            parseMakeOp(element,data);

        //Flatten
        if(operatorEle.tagName()=="operator"&&operatorEle.firstChild().toElement().tagName()=="FlattenOp")
            parseFlattenOp(element,data);

        //Iterator
        if(operatorEle.tagName()=="operator"&&operatorEle.firstChild().toElement().tagName()=="IteratorOp")
            parseIteratorOp(element,data);

        //Partiallterator
        if(operatorEle.tagName()=="operator"&&operatorEle.firstChild().toElement().tagName()=="PartialIteratorOp")
            parsePartialIteratorOp(element,data);

        //自定义操作符
        if(operatorEle.tagName()=="operator"&&operatorEle.firstChild().toElement().tagName()=="OpCall")
            parseOpCall(element,data);

        //Boolean Activate
        if(operatorEle.tagName()=="operator"&&(operatorEle.firstChild().toElement().tagName()=="ActivateOp"||operatorEle.firstChild().toElement().tagName()=="ActivateNoInitOp"))
        {
            m_operator.logList.append("存在REDACE不支持的Boolean Activate操作符;");
            data.isUnsupport=true;
        }

        //Restart
        if(operatorEle.tagName()=="operator"&&operatorEle.firstChild().toElement().tagName()=="RestartOp")
        {
            m_operator.logList.append("存在REDACE不支持的Restart操作符;");
            data.isUnsupport=true;
        }

    }

    if(tagName=="TransposeOp")
    {
        m_operator.logList.append("存在REDACE不支持的操作符Transpose;");
        data.isUnsupport=true;
    }

    if(tagName=="NumericCastOp")
    {
        m_operator.logList.append("存在REDACE不支持的操作符NumericCast;");
        data.isUnsupport=true;
    }



}

void OperatorImporter::parseUnaryOp(const QDomElement &element,Equation &data)
{
    data.operatorType="UnaryOp";

    if(!element.hasAttribute("operator"))
        return;

    QString operatorName=element.attribute("operator");

    //Unary Minus取反运算
    if(operatorName=="-")
        data.operatorName="Unary Minus";

    //Not非运算
    if(operatorName=="not")
        data.operatorName="Not";

    //Convert To Integer强制转换为整数运算
    if(operatorName=="int")
        data.operatorName="Convert To Integer";

    //Convert To Real强制转换换浮点数运算
    if(operatorName=="real")
        data.operatorName="Convert To Real";

    //Reverse
    if(operatorName=="reverse")
    {
        m_operator.logList.append("存在REDACE不支持的Reverse操作符;");
        data.isUnsupport=true;
    }

    QDomElement operandEle=element.firstChild().toElement();

    if(operandEle.tagName()!="operand")
        return;

    QDomElement idExpressionEle=operandEle.firstChild().toElement();

    data.unaryOp.constVarRef=parseIdExpression(idExpressionEle);

}

void OperatorImporter::parseBinaryOp(const QDomElement &element,Equation &data)
{
    data.operatorType="BinaryOp";

    if(!element.hasAttribute("operator"))
        return;

    QString operatorName=element.attribute("operator");

    //Minus 减法运算
    if(operatorName=="-")
        data.operatorName="Minus";

    //Polymorphic Division 除法运算（输出值为浮点数）
    if(operatorName=="/")
        data.operatorName="Polymorphic Division";

    //Integer Division 除法运算（输出值为整数）
    if(operatorName=="div")
        data.operatorName="Integer Division";

    //Modulo 求余运算
    if(operatorName=="mod")
        data.operatorName="Modulo";

    //Strictly Less Than  <
    if(operatorName=="<")
        data.operatorName="Strictly Less Than";

    //Less Than Or Equal   <=
    if(operatorName=="<=")
        data.operatorName="Less Than Or Equal";

    //Strictly Greater Than  >
    if(operatorName==">")
        data.operatorName="Strictly Greater Than";

    //Greater Than Or Equal   >=
    if(operatorName==">=")
        data.operatorName="Greater Than Or Equal";

    //Different  !=
    if(operatorName=="<>")
        data.operatorName="Different";

    //Equal    ==
    if(operatorName=="=")
        data.operatorName="Equal";

    if(operatorName=="times")
    {
        m_operator.logList.append("存在REDACE不支持的Times操作符;");
        data.isUnsupport=true;
    }

    QDomElement operandsEle=element.firstChild().toElement();

    if(operandsEle.tagName()!="operands")
        return;

    QDomNodeList idExpressionNodes=operandsEle.childNodes();

    for(int i=0;i<idExpressionNodes.size();i++)
    {
        data.binaryOp.constVarRefs.append(parseIdExpression(idExpressionNodes.at(i).toElement()));
    }

}

void OperatorImporter::parseNAryOp(const QDomElement &element,Equation &data)
{
    data.operatorType="NAryOp";

    if(!element.hasAttribute("operator"))
        return;

    QString operatorName=element.attribute("operator");

    //Plus加法运算
    if(operatorName=="+")
        data.operatorName="Plus";

    //Multiplication乘法运算
    if(operatorName=="*")
        data.operatorName="Multiplication";

    //And 与运算
    if(operatorName=="and")
        data.operatorName="And";

    //Or 或运算
    if(operatorName=="or")
        data.operatorName="Or";

    //Exclusive Or异或运算
    if(operatorName=="xor")
        data.operatorName="Exclusive Or";

    //Concatenation
    if(operatorName=="@")
    {
        m_operator.logList.append("存在REDACE不支持的Concatenation操作符;");
        data.isUnsupport=true;
    }

    QDomElement operandsEle=element.firstChild().toElement();

    if(operandsEle.tagName()!="operands")
        return;

    QDomNodeList idExpressionNodes=operandsEle.childNodes();

    for(int i=0;i<idExpressionNodes.size();i++)
    {
        data.nAryOp.constVarRefs.append(parseIdExpression(idExpressionNodes.at(i).toElement()));
    }

}

void OperatorImporter::parsePreOp(const QDomElement &element,Equation &data)
{
    data.operatorType="PreOp";

    QDomElement flowEle=element.firstChild().toElement();
    if(flowEle.tagName()!="flow")
        return;

    QDomElement listEle=flowEle.firstChild().toElement();
    if(listEle.tagName()!="ListExpression")
        return;

    QDomElement itemsEle=listEle.firstChild().toElement();
    if(itemsEle.tagName()!="items")
        return;

    QDomNodeList itemsChilds=itemsEle.childNodes();

    for(int i=0;i<itemsChilds.size();i++)
    {
        data.preOp.flows.append(parseIdExpression(itemsChilds.at(i).toElement()));
    }

}

void OperatorImporter::parseInitOp(const QDomElement &element,Equation &data)
{
    data.operatorType="InitOp";

    QDomElement valueEle=element.firstChild().toElement();
    if(valueEle.tagName()!="value")
        return;

    QDomElement flowEle=element.firstChild().nextSibling().toElement();
    if(flowEle.tagName()!="flow")
        return;

    //参数
    QDomNodeList valueChilds=valueEle.firstChild().firstChild().childNodes();
    for(int i=0;i<valueChilds.size();i++)
    {
        if(!valueChilds.at(i).isComment())
        {
            QDomElement valueChildEle=valueChilds.at(i).toElement();

            data.initOp.parameters.append(parseParameter(valueChildEle));
        }
    }

    //输入端口
    QDomNodeList flowChilds=flowEle.firstChild().firstChild().childNodes();
    for(int i=0;i<flowChilds.size();i++)
    {
        QDomElement flowChildEle=flowChilds.at(i).toElement();

        data.initOp.flows.append(parseIdExpression(flowChildEle));
    }

}

void OperatorImporter::parseFbyOp(const QDomElement &element,Equation &data)
{
    data.operatorType="FbyOp";

    QDomElement flowsEle=element.firstChild().toElement();
    if(flowsEle.tagName()!="flows")
        return;

    QDomElement delayEle=element.firstChild().nextSibling().toElement();
    if(delayEle.tagName()!="delay")
        return;

    QDomElement valuesEle=element.firstChild().nextSibling().nextSibling().toElement();
    if(valuesEle.tagName()!="values")
        return;

    //输入
    QDomNodeList flowsChilds=flowsEle.childNodes();
    for(int i=0;i<flowsChilds.size();i++)
    {
        QDomElement flowChildEle=flowsChilds.at(i).toElement();

        data.fbyOp.flows.append(parseIdExpression(flowChildEle));
    }

    //delay
    if(delayEle.childNodes().size()==2)
    {
        QDomElement delayChild=delayEle.childNodes().at(1).toElement();

        data.fbyOp.delay=parseParameter(delayChild);
    }
    else {
        QDomElement delayChild=delayEle.firstChild().toElement();

        data.fbyOp.delay=parseParameter(delayChild);
    }

    //其他参数
    QDomNodeList valuesChilds=valuesEle.childNodes();
    for(int i=0;i<valuesChilds.size();i++)
    {
        if(!valuesChilds.at(i).isComment())
        {
            QDomElement valueChildEle=valuesChilds.at(i).toElement();

            data.fbyOp.parameters.append(parseParameter(valueChildEle));
        }
    }
}

void OperatorImporter::parsePrjOp(const QDomElement &element,Equation &data)
{
    data.operatorType="PrjOp";

    QDomElement flowEle=element.firstChild().toElement();
    if(flowEle.tagName()!="flow")
        return;

    QDomElement withEle=element.firstChild().nextSibling().toElement();
    if(withEle.tagName()!="with")
        return;

    //输入
    QDomElement flowChildEle=flowEle.firstChild().toElement();
    data.prjOp.flow=parseIdExpression(flowChildEle);

    //参数
    QDomNodeList withChilds=withEle.childNodes();
    for(int i=0;i<withChilds.size();i++)
    {
        if(!withChilds.at(i).isComment())
        {
            QDomElement withChildEle=withChilds.at(i).toElement();

            if(withChildEle.tagName()!="Label")
            {
                data.prjOp.parameters.append(parseParameter(withChildEle));
            }
            else
            {
                parameter para;
                para.value=withChildEle.attribute("name");
                data.prjOp.parameters.append(para);
            }

        }

        //        QDomElement valueChildEle=valueChilds.at(i).toElement();

        //        parameter para;

        //        //立即数
        //        if(valueChildEle.tagName()=="ConstValue")
        //        {
        //            para.isImmediate=true;
        //            para.value=valueChildEle.attribute("value");
        //        }

        //        //非立即数
        //        if(valueChildEle.tagName()=="IdExpression")
        //        {
        //            para.value=parseIdExpression(valueChildEle);
        //        }

        //        data.prjOp.parameters.append(para);
    }
}

void OperatorImporter::parseSliceOp(const QDomElement &element,Equation &data)
{
    data.operatorType="SliceOp";

    QDomElement arrayEle=element.firstChild().toElement();
    if(arrayEle.tagName()!="array")
        return;

    QDomElement fromIndexEle=element.firstChild().nextSibling().toElement();
    if(fromIndexEle.tagName()!="fromIndex")
        return;

    QDomElement toIndexEle=element.firstChild().nextSibling().nextSibling().toElement();
    if(toIndexEle.tagName()!="toIndex")
        return;

    //array
    data.sliceOp.array=parseIdExpression(arrayEle.firstChild().toElement());

    //fromIndex
    if(fromIndexEle.childNodes().size()==2)
    {
        data.sliceOp.fromIndex=parseParameter(fromIndexEle.childNodes().at(1).toElement());
    }
    else {
        data.sliceOp.fromIndex=parseParameter(fromIndexEle.firstChild().toElement());
    }


    //toIndex
    if(toIndexEle.childNodes().size()==2)
    {
        data.sliceOp.toIndex=parseParameter(toIndexEle.childNodes().at(1).toElement());
    }
    else {
        data.sliceOp.toIndex=parseParameter(toIndexEle.firstChild().toElement());
    }


}

void OperatorImporter::parsePrjDynOp(const QDomElement &element,Equation &data)
{
    data.operatorType="PrjDynOp";

    QDomElement arrayEle=element.firstChild().toElement();
    if(arrayEle.tagName()!="array")
        return;

    QDomElement indexesEle=element.firstChild().nextSibling().toElement();
    if(indexesEle.tagName()!="indexes")
        return;

    QDomElement defaultEle=element.firstChild().nextSibling().nextSibling().toElement();
    if(defaultEle.tagName()!="default")
        return;

    data.prjDynOp.array=parseIdExpression(arrayEle.firstChild().toElement());

    QDomNodeList indexesChilds=indexesEle.childNodes();
    for(int i=0;i<indexesChilds.size();i++)
    {
        if(!indexesChilds.at(i).isComment())
        {
            QDomElement indexesChildEle=indexesChilds.at(i).toElement();

            data.prjDynOp.indexes.append(parseParameter(indexesChildEle));
        }

    }

    if(defaultEle.childNodes().size()==2)
    {
        data.prjDynOp.defaultpara=parseParameter(defaultEle.childNodes().at(1).toElement());
    }
    else {
        data.prjDynOp.defaultpara=parseParameter(defaultEle.firstChild().toElement());
    }

}

void OperatorImporter::parseDataStructOp(const QDomElement &element,Equation &data)
{
    data.operatorType="DataStructOp";

    QDomElement dataEle=element.firstChild().toElement();

    if(dataEle.tagName()!="data")
        return;

    QDomNodeList labels=dataEle.childNodes();

    for(int i=0;i<labels.size();i++)
    {
        QDomElement labelEle=labels.at(i).toElement();

        label item;
        item.labelName=labelEle.attribute("label");
        item.value=parseIdExpression(labelEle.firstChild().firstChild().toElement());

        data.dataStructOp.labels.append(item);

    }

}

void OperatorImporter::parseScalarToVectorOp(const QDomElement &element,Equation &data)
{
    data.operatorType="ScalarToVectorOp";

    QDomElement flowEle=element.firstChild().toElement();
    if(flowEle.tagName()!="flow")
        return;

    QDomElement sizeEle=element.firstChild().nextSibling().toElement();
    if(sizeEle.tagName()!="size")
        return;

    QDomNodeList itemsChilds=flowEle.firstChild().firstChild().childNodes();

    for(int i=0;i<itemsChilds.size();i++)
    {
        QDomElement itemsChildEle=itemsChilds.at(i).toElement();
        data.scalarToVectorOp.flows.append(parseIdExpression(itemsChildEle));
    }

    if(sizeEle.childNodes().size()==2)
    {
        data.scalarToVectorOp.size=parseParameter(sizeEle.childNodes().at(1).toElement());
    }
    else {
        data.scalarToVectorOp.size=parseParameter(sizeEle.firstChild().toElement());
    }

}

void OperatorImporter::parseDataArrayOp(const QDomElement &element,Equation &data)
{
    data.operatorType="DataArrayOp";

    QDomElement dataEle=element.firstChild().toElement();

    if(dataEle.tagName()!="data")
        return;

    QDomNodeList dataChilds=dataEle.childNodes();
    for(int i=0;i<dataChilds.size();i++)
    {
        QDomElement dataChildEle=dataChilds.at(i).toElement();
        data.dataArrayOp.datas.append(parseIdExpression(dataChildEle));
    }
}

void OperatorImporter::parseChgIthOp(const QDomElement &element,Equation &data)
{
    data.operatorType="ChgIthOp";

    QDomElement flowEle=element.firstChild().toElement();
    if(flowEle.tagName()!="flow")
        return;

    QDomElement withEle=element.firstChild().nextSibling().toElement();
    if(withEle.tagName()!="with")
        return;

    QDomElement valueEle=element.firstChild().nextSibling().nextSibling().toElement();
    if(valueEle.tagName()!="value")
        return;

    data.chgIthOp.flow=parseIdExpression(flowEle.firstChild().toElement());

    QDomNodeList withChilds=withEle.childNodes();
    for(int i=0;i<withChilds.size();i++)
    {
        if(!withChilds.at(i).isComment())
        {
            QDomElement withChildEle=withChilds.at(i).toElement();

            if(withChildEle.tagName()!="Label")
            {
                data.chgIthOp.parameters.append(parseParameter(withChildEle));
            }
            else
            {
                parameter para;
                para.value=withChildEle.attribute("name");
                data.chgIthOp.parameters.append(para);
            }

        }
    }

    data.chgIthOp.value=parseIdExpression(valueEle.firstChild().toElement());
}

void OperatorImporter::parseIfThenElseOp(const QDomElement &element,Equation &data)
{
    data.operatorType="IfThenElseOp";

    QDomElement ifEle=element.firstChild().toElement();
    if(ifEle.tagName()!="if")
        return;

    QDomElement thenEle=element.firstChild().nextSibling().toElement();
    if(thenEle.tagName()!="then")
        return;

    QDomElement elseEle=element.firstChild().nextSibling().nextSibling().toElement();
    if(elseEle.tagName()!="else")
        return;

    data.ifThenElseOp.ifValue=parseIdExpression(ifEle.firstChild().toElement());

    QDomNodeList thenChilds=thenEle.firstChild().firstChild().childNodes();
    for(int i=0;i<thenChilds.size();i++)
    {
        QDomElement thenChildEle=thenChilds.at(i).toElement();
        data.ifThenElseOp.thens.append(parseIdExpression(thenChildEle));
    }

    QDomNodeList elseChilds=elseEle.firstChild().firstChild().childNodes();
    for(int i=0;i<elseChilds.size();i++)
    {
        QDomElement elseChildEle=elseChilds.at(i).toElement();
        data.ifThenElseOp.elses.append(parseIdExpression(elseChildEle));
    }
}

void OperatorImporter::parseCaseOp(const QDomElement &element,Equation &data)
{
    data.operatorType="CaseOp";

    QDomElement switchEle=element.firstChild().toElement();
    if(switchEle.tagName()!="switch")
        return;

    QDomElement casesEle=element.firstChild().nextSibling().toElement();
    if(casesEle.tagName()!="cases")
        return;

    data.caseOp.switchValue=parseIdExpression(switchEle.firstChild().toElement());

    QDomNodeList casesChilds=casesEle.childNodes();
    for(int i=0;i<(casesChilds.size()-1);i++)
    {
        QDomElement casesChildEle=casesChilds.at(i).toElement();

        label item;
        item.labelName=casesChildEle.attribute("pattern");
        item.value=parseIdExpression(casesChildEle.firstChild().firstChild().toElement());
        data.caseOp.cases.append(item);
    }

    data.caseOp.defaultValue=parseIdExpression(casesChilds.at(casesChilds.size()).toElement());
}

void OperatorImporter::parseMakeOp(const QDomElement &element,Equation &data)
{
    data.operatorType="MakeOp";

    QDomElement operatorEle=element.firstChild().toElement();
    if(operatorEle.tagName()!="operator")
        return;

    QDomElement callsEle=operatorEle.nextSibling().toElement();

    data.makeOp.typeRef=operatorEle.firstChild().firstChild().firstChild().toElement().attribute("name");

    QDomNodeList callsChilds=callsEle.childNodes();
    for(int i=0;i<callsChilds.size();i++)
    {
        QDomElement callsChildEle=callsChilds.at(i).toElement();
        data.makeOp.calls.append(parseIdExpression(callsChildEle));
    }
}

void OperatorImporter::parseFlattenOp(const QDomElement &element,Equation &data)
{
    data.operatorType="FlattenOp";

    QDomElement operatorEle=element.firstChild().toElement();
    if(operatorEle.tagName()!="operator")
        return;

    QDomElement callsEle=element.firstChild().nextSibling().toElement();
    if(callsEle.tagName()!="callParameters")
        return;

    data.flattenOp.typeRef=operatorEle.firstChild().firstChild().firstChild().toElement().attribute("name");

    data.flattenOp.call=parseIdExpression(callsEle.firstChild().toElement());

}

void OperatorImporter::parseIteratorOp(const QDomElement &element,Equation &data)
{
    data.operatorType="IteratorOp";

    QDomElement operatorEle=element.firstChild().toElement();
    if(operatorEle.tagName()!="operator")
        return;

    QDomElement callsEle=operatorEle.nextSibling().toElement();

    QDomElement iteratorEle=operatorEle.firstChild().toElement();

    data.iteratorOp.iteratorType=iteratorEle.attribute("iterator");

    operatorEle=iteratorEle.firstChild().toElement();
    if(operatorEle.tagName()!="operator")
        return;

    QDomElement sizeEle=operatorEle.nextSibling().toElement();
    if(sizeEle.tagName()!="size")
        return;

    QDomElement ele=operatorEle.firstChild().toElement();

    //组合操作符或用户操作符
    if(ele.tagName()=="OpCall")
    {
        data.iteratorOp.operatorRef=ele.firstChild().firstChild().toElement().attribute("name");

        //判断是否为自定义操作符
        if(data.iteratorOp.operatorRef.at(data.iteratorOp.operatorRef.length()-1)=='$')
        {
            data.iteratorOp.isRef=false;
        }
        else {
            data.iteratorOp.isRef=true;
        }
    }

    //Make
    if(ele.tagName()=="MakeOp")
    {
        m_operator.logList.append("存在REDACE不支持的Make的高阶操作符;");
        data.isUnsupport=true;
        data.iteratorOp.isMakeOp=true;
        data.iteratorOp.makeRef=ele.firstChild().firstChild().toElement().attribute("name");
    }

    //Flatten
    if(ele.tagName()=="FlattenOp")
    {
        m_operator.logList.append("存在REDACE不支持的Flatten的高阶操作符;");
        data.isUnsupport=true;
        data.iteratorOp.isFlattenOp=true;
        data.iteratorOp.flattenRef=ele.firstChild().firstChild().toElement().attribute("name");
    }

    if(sizeEle.childNodes().size()==2)
    {
        data.iteratorOp.size=parseParameter(sizeEle.childNodes().at(1).toElement());
    }
    else {
        data.iteratorOp.size=parseParameter(sizeEle.firstChild().toElement());
    }

    if(data.iteratorOp.size.value==m_operator.parameter)
        data.isParaHigh=true;

    QDomNodeList callsChilds=callsEle.childNodes();
    for(int i=0;i<callsChilds.size();i++)
    {
        QDomElement callsChildEle=callsChilds.at(i).toElement();
        data.iteratorOp.calls.append(parseIdExpression(callsChildEle));
    }

    if(data.iteratorOp.isRef==true)
    {
        opcallOperator opcall;
        opcall.operatorName=m_operator.operatorName;
        opcall.opcallName=data.iteratorOp.operatorRef;

        opcall.equation=data;
        m_operator.opCallList.append(opcall);
    }
}

void OperatorImporter::parsePartialIteratorOp(const QDomElement &element,Equation &data)
{
    data.operatorType="PartialIteratorOp";

    QDomElement operatorEle=element.firstChild().toElement();
    if(operatorEle.tagName()!="operator")
        return;

    QDomElement callsEle=operatorEle.nextSibling().toElement();


    QDomElement partialIteratorEle=operatorEle.firstChild().toElement();

    data.partialIteratorOp.partialIteratorType=partialIteratorEle.attribute("iterator");

    operatorEle=partialIteratorEle.firstChild().toElement();
    if(operatorEle.tagName()!="operator")
        return;

    QDomElement sizeEle=operatorEle.nextSibling().toElement();
    if(sizeEle.tagName()!="size")
        return;

    QDomElement ifEle=sizeEle.nextSibling().toElement();
    if(ifEle.tagName()!="if")
        return;

    QDomElement defaultEle=ifEle.nextSibling().toElement();

    if(!defaultEle.isNull())
        data.partialIteratorOp.hasDefault=true;

    QDomElement ele=operatorEle.firstChild().toElement();

    //组合操作符或用户操作符
    if(ele.tagName()=="OpCall")
    {
        data.partialIteratorOp.operatorRef=ele.firstChild().firstChild().toElement().attribute("name");

        //判断是否为自定义操作符
        if(data.partialIteratorOp.operatorRef.at(data.partialIteratorOp.operatorRef.length()-1)=='$')
        {
            data.partialIteratorOp.isRef=false;
        }
        else {
            data.partialIteratorOp.isRef=true;
        }
    }

    //Make
    if(ele.tagName()=="MakeOp")
    {
        m_operator.logList.append("存在REDACE不支持的Make的高阶操作符;");
        data.isUnsupport=true;
        data.partialIteratorOp.isMakeOp=true;
        data.partialIteratorOp.makeRef=ele.firstChild().firstChild().toElement().attribute("name");
    }

    //Flatten
    if(ele.tagName()=="FlattenOp")
    {
        m_operator.logList.append("存在REDACE不支持的Flatten的高阶操作符;");
        data.isUnsupport=true;
        data.partialIteratorOp.isFlattenOp=true;
        data.partialIteratorOp.flattenRef=ele.firstChild().firstChild().toElement().attribute("name");
    }

    //    data.partialIteratorOp.size=sizeEle.firstChild().toElement().attribute("value");

    if(sizeEle.childNodes().size()==2)
    {
        data.partialIteratorOp.size=parseParameter(sizeEle.childNodes().at(1).toElement());
    }
    else {
        data.partialIteratorOp.size=parseParameter(sizeEle.firstChild().toElement());
    }

    if(data.partialIteratorOp.size.value==m_operator.parameter)
        data.isParaHigh=true;

    data.partialIteratorOp.ifValue=parseIdExpression(ifEle.firstChild().toElement());

    if(data.partialIteratorOp.hasDefault==true)
    {
        if(defaultEle.firstChild().firstChild().childNodes().size()==2)
        {
            data.partialIteratorOp.defaultValue=parseParameter(defaultEle.firstChild().firstChild().childNodes().at(1).toElement());
        }
        else {
            data.partialIteratorOp.defaultValue=parseParameter(defaultEle.firstChild().firstChild().firstChild().toElement());
        }
    }


    QDomNodeList callsChilds=callsEle.childNodes();
    for(int i=0;i<callsChilds.size();i++)
    {
        QDomElement callsChildEle=callsChilds.at(i).toElement();
        data.partialIteratorOp.calls.append(parseIdExpression(callsChildEle));
    }

    if(data.partialIteratorOp.isRef==true)
    {
        opcallOperator opcall;
        opcall.operatorName=m_operator.operatorName;
        opcall.opcallName=data.partialIteratorOp.operatorRef;

        opcall.equation=data;
        m_operator.opCallList.append(opcall);
    }

}

void OperatorImporter::parseOpCall(const QDomElement &element,Equation &data)
{
    data.operatorType="OpCall";

    QDomElement operatorEle;

    operatorEle=element.firstChild().toElement();

    QDomElement instanceParaEle;

    QDomNodeList nodeList=operatorEle.firstChild().childNodes();

    for(int i=0;i<nodeList.size();i++)
    {

        //判断是否包含参数
        if(nodeList.at(i).toElement().tagName()=="instanceParameters")
        {
            data.isParaHigh=true;
            instanceParaEle=nodeList.at(i).toElement();

            if(instanceParaEle.childNodes().size()==2)
            {
                data.paraValue=parseParameter(instanceParaEle.childNodes().at(1).toElement());
            }
            else {
                data.paraValue=parseParameter(instanceParaEle.firstChild().toElement());
            }

        }
    }

    QDomElement callsEle=operatorEle.nextSibling().toElement();

    data.opCall.operatorRef=operatorEle.firstChild().firstChild().firstChild().toElement().attribute("name");

    //保存所有调用的操作符
    opcallOperator opcall;
    opcall.operatorName=m_operator.operatorName;
    opcall.opcallName=data.opCall.operatorRef;

    if(data.isParaHigh==true)
    {
        opcallParaOperator opcall;
        opcall.paraValue=data.paraValue;
        opcall.operatorName=data.opCall.operatorRef;

        data.opCall.operatorRef=opcall.operatorName+"_"+opcall.paraValue.value;

        m_operator.paraOperatorList.append(opcall);
    }

    QDomNodeList callsChilds=callsEle.childNodes();
    for(int i=0;i<callsChilds.size();i++)
    {
        QDomElement callsChildEle=callsChilds.at(i).toElement();
        data.opCall.calls.append(parseIdExpression(callsChildEle));
    }

    opcall.equation=data;
    m_operator.opCallList.append(opcall);

}

QString OperatorImporter::parseIdExpression(const QDomElement &element)
{
    QString refName;
    QDomNode pathNode=element.firstChild();

    if(pathNode.toElement().tagName()!="path")
    {
        return refName;
    }

    if(pathNode.firstChild().isNull())
        return refName;

    QDomElement constVarRefEle=pathNode.firstChild().toElement();

    if(constVarRefEle.tagName()=="NullRef")
        return refName;

    if(constVarRefEle.tagName()=="ConstVarRef"&&constVarRefEle.hasAttribute("name"))
    {
        refName=constVarRefEle.attribute("name");

    }

    return refName;

}

parameter OperatorImporter::parseParameter(const QDomElement &element)
{
    parameter para;

    para.node=element;
    //立即数
    if(element.tagName()=="ConstValue")
    {
        para.isImmediate=true;
        para.value=element.attribute("value");
    }

    //非立即数
    if(element.tagName()=="IdExpression")
    {
        para.value=parseIdExpression(element);
    }

    //表达式
    if(para.value.isEmpty())
    {
        para.isImmediate=true;
        para.value=element.previousSibling().nodeValue();
    }

    return para;
}

void OperatorImporter::parsePragmas(const QDomElement &element)
{
    QDomElement operatorEle=element.firstChild().toElement();
    if(operatorEle.tagName()!="ed:Operator")
        return;

    m_operator.oid=operatorEle.attribute("oid");

    QDomNodeList  operatorChilds=operatorEle.childNodes();
    for(int i=0;i<operatorChilds.size();i++)
    {
        QDomElement operatorChild=operatorChilds.at(i).toElement();

        //comment
        if(operatorChild.tagName()=="comment")
            m_operator.comment=operatorChild.text();

        //diagrams
        if(operatorChild.tagName()=="diagrams")
        {
            QDomNodeList diagramList=operatorChild.childNodes();
            for(int i=0;i<diagramList.size();i++)
            {
                QDomElement diagEle=diagramList.at(i).toElement();

                parseDiagram(diagEle);
            }
        }
    }

}

void OperatorImporter::parseDiagram(const QDomElement &element)
{
    Diagram diag;
    diag.oid=element.attribute("oid");
    diag.redaceOid=QUuid::createUuid().toString(QUuid::WithoutBraces);
    diag.name=element.attribute("name");
    diag.landscape=element.attribute("landscape");

    if(element.hasChildNodes())
    {
        QDomElement presentationElements=element.firstChild().toElement();

        QDomNodeList equationGEList=presentationElements.childNodes();
        for(int i=0;i<equationGEList.size();i++)
        {
            QDomElement ele=equationGEList.at(i).toElement();
            if(ele.tagName()=="EquationGE")
            {
                QDomElement positionEle=ele.firstChild().toElement();
                QDomElement sizeEle=positionEle.nextSibling().toElement();

                for(int j=0;j<m_operator.equations.size();j++)
                {
                    //                    int equationIndex;
                    if(ele.attribute("presentable")==m_operator.equations.at(j).oid)
                    {
                        //                        equationIndex=j;

                        m_operator.equations[j].x=positionEle.firstChild().toElement().attribute("x").toInt();
                        m_operator.equations[j].y=positionEle.firstChild().toElement().attribute("y").toInt();
                        m_operator.equations[j].width=sizeEle.firstChild().toElement().attribute("width").toInt();
                        m_operator.equations[j].height=sizeEle.firstChild().toElement().attribute("height").toInt();
                        m_operator.equations[j].pageId=diag.redaceOid;

                        diag.equations.append(m_operator.equations.at(j));
                    }
                }

            }

            if(ele.tagName()=="Edge")
            {
                Line line;
                line.leftIndex=ele.attribute("leftVarIndex");
                line.rightIndex=ele.attribute("rightExprIndex");
                line.leftEquationOid=ele.attribute("srcEquation");
                line.rightEquationOid=ele.attribute("dstEquation");

                QDomNodeList pointList=ele.firstChild().childNodes();

                //去掉重复的点。奇数重复点去掉，偶数重复点保留
                struct Point
                {
                    int x;
                    int y;
                };

                QList<Point> points;

                for(int j=0;j<pointList.size();j++)
                {
                    Point point;
                    point.x=pointList.at(j).toElement().attribute("x").toInt();
                    point.y=pointList.at(j).toElement().attribute("y").toInt();
                    points.append(point);
                }

                QList<int> indexes;
                for(int j=1;j<points.size();j++)
                {
                    int xL=points.at(j).x-points.at(j-1).x;
                    int yL=points.at(j).y-points.at(j-1).y;

                    if(xL==0&&yL==0&&j%2==0)
                    {
                        indexes.append(j);
                    }
                }

                QList<int> pointRemoveIndex;
                for(int j=0;j<indexes.size();j++)
                {
                    pointRemoveIndex.append(j);
                    //                    points.removeAt(indexes.at(j));
                }

                for(int i=pointRemoveIndex.size()-1;i>=0;i--)
                {
                    points.removeAt(pointRemoveIndex.at(i));
                }

                for(int j=1;j<(points.size()-1);j=j+2)
                {
                    LineLength lineLength;
                    lineLength.hLength=points.at(j).x-points.at(j-1).x;
                    lineLength.zLength=points.at(j+1).y-points.at(j).y;
                    line.lineLengthList.append(lineLength);
                }

                diag.lineList.append(line);
            }
        }
    }

    m_operator.diagrams.append(diag);
}

QString OperatorImporter::judgeVarType(QString &varName)
{
    for(int i=0;i<m_operator.variables.size();i++)
    {
        Variable var=m_operator.variables.at(i);
        if(var.name==varName)
        {
            return var.type;
        }
    }
}
